私の仕事では、完全に機能する三目並べプログラムを作成する必要はありません。X と O をボードに印刷できるようにする必要があります。
この時点で、「X」と「O」をボードに印刷する必要があり、これが最終段階です。
これが私のコードです:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Declare the variables
//Create the board
//Initialize the board with all blanks
//Print to screen
//Prompt user for letter 'X', 'O' or 'q' to quit
//if the input is q, then quit.
//if the input is X or O then select positions.
//prompt user to choose rows & columns to mark X O positions
//declare the variables
char board[3][4], input; //input is for the X O q
char selectRows, selectColumns; //these are for choosing position to mark X or O
int rows, columns;
//create the basic empty board
for ( rows = 0 ; rows <3 ; rows++ )
{
for ( columns = 0 ; columns < 4 ; columns++ )
{
//Initialize array to blanks (' ')
board[rows][columns] = '|';
//print to screen
printf( "%c ", board[rows][columns] );
}
printf("\n\n\n");
}
//prompt the user to input X or O
printf( "\nHit X or O. 'q' to quit\n" );
scanf("%c", &input);
while ( input != 'q' )
{
//if the input is 'X' or 'O'
if ( input == 'X' || input == 'O' )
{
//select rows
printf("Choose 1 - 3 For Rows ");
scanf( "\n%c", &selectRows );
//select columns
printf("Choose 1 - 3 For Columns ");
scanf( "\n%c", &selectColumns );
//Print X or O on the board
if ( selectRows == 1 && selectColumns == 1 )
//prompt user to hit in X or O, q to quit again
printf( "\nHit X or O. 'q' to quit\n" );
scanf("%c", &input);
}
} //end while
}//end main
そのため、空のボードを印刷し、ユーザーに X または O または q を入力してゲームを終了するように要求することができました。
ただし、X と O をボードに印刷する方法がわかりません。
input
「X」または「O」を含む を正しい位置に配置するにはどうすればよいですか? これらのステートメントは以下に記載する必要があると思いますif ( selectRows == 1 && selectColumns == 1 )
正解できれば、他のとif ( selectRows == 1 && selectColumns == 1 )
についても正解できるはずです。 selectRows
selectColumns