Hi, I am writing a tic tac toe game and cant get it to print out the board with an X after the player has made a move. Any help would be greatly appreciated.
Thanks
Code:
bool playerturn=false; //false = my turn, true = computer turn
bool gameover=false;
int x; //X in Tic Tac Toe
int o; //O in Tic Tac toe
int playermove[4];
int computermove[4];
int board[3][3]= {1,2,3,4,5,6,7,8,'x'};
int totalmoves[9];
int move;
move = 0;
// while (gameover == false)
// {
for(int row = 0; row < 3; row ++)
{
for(int col = 0; col < 3; col ++)
{
cout << board[row][col] << " ";
}
cout << endl;
}
cout<<"Enter a move [" << move << "] ";
cin>>playermove[move];
switch (playermove[move])
{
case 1:
board[0][0] =='x';
playermove[0]=='x';
break;
case 2:
board[0][1] =='x';
playermove[0]=='x';
break;
case 3:
board[0][2] =='x';
playermove[0]=='x';
break;
case 4:
board[1][0] =='x';
playermove[0]=='x';
break;
case 5:
board[1][1] =='x';
playermove[0]=='x';
break;
case 6:
board[1][2] ='x';
playermove[0]=='x';
break;
case 7:
board[2][0] =='x';
playermove[0]=='x';
break;
case 8:
board[2][1] =='x';
playermove[0]=='x';
break;
case 9:
board[2][2] =='x';
playermove[0]=='x';
break;
default:
cout<<"Enter a valid statement"<<endl;
}
move ++;
for(int row = 0; row < 3; row ++)
{
for(int col = 0; col < 3; col ++)
{
cout << board[row][col] << " ";
}
cout << endl;
}