Hi i'm trying to do a program that allows two users or one to play a game of tic tac toe....my program goes well until someone wins and the program keeps asking for the next X or O to be entered...could someone help me?
Code:
#include <iostream>
using namespace std;
int main()
{
char game[3][3]={{'*','*','*'},{'*','*','*'},{'*','*','*'}};
char choice;
int row, column, count=0, winner=0;
cout<<"Lets play a game of TicTacToe! Here's the starting game board: "<<endl;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
cout << game[i][j]<<" ";
}
cout<<endl;
}
do
{
cout<<"Are you X or O? Please enter a captial X or O: ";
cin>>choice;
cout<<"Enter the row and column to place your "<<choice<<". ";
cin>>row>>column;
game[row][column]=choice;
count+=1;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
cout << game[i][j]<<" ";
}
cout<<endl;
}
if(game[0][0]=='X' && game[0][1]=='X' && game[0][2]=='X')
{
winner=1;
cout<<game[0][0]<<" wins!!"<<endl;
}
else if(game[1][0]=='X' && game[1][1]=='X' && game[1][2]=='X')
{
winner=1;
cout<<game[1][0]<<" wins!!"<<endl;
}
else if(game[2][0]='X' && game[2][1]=='X' && game[2][2]=='X')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][0]=='X' && game[1][0]=='X' && game[2][0]=='X')
{
winner=1;
cout <<game[0][0]<<" wins!!"<<endl;
}
else if(game[0][1]=='X' && game[1][1]=='X' && game[2][1]=='X')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][2]=='X' && game[1][2]=='X' && game[2][2]=='X')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][0]=='X' && game[1][1]=='X' && game[2][2]=='X')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][2]=='X' && game[1][1]=='X' && game[2][0]=='X')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][0]=='O' && game[0][1]=='O' && game[0][2]=='O')
{
winner=1;
cout<<game[0][0]<<" wins!!"<<endl;
}
else if(game[1][0]=='O' && game[1][1]=='O' && game[1][2]=='O')
{
winner=1;
cout<<game[1][0]<<" wins!!"<<endl;
}
else if(game[2][0]=='O' && game[2][1]=='O' && game[2][2]=='O')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][0]=='O' && game[1][0]=='O' && game[2][0]=='O')
{
winner=1;
cout <<game[0][0]<<" wins!!"<<endl;
}
else if(game[0][1]=='O' && game[1][1]=='O' && game[2][1]=='O')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][2]=='O' && game[1][2]=='O' && game[2][2]=='O')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][0]=='O' && game[1][1]=='O' && game[2][2]=='O')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(game[0][2]=='O' && game[1][1]=='O' && game[2][0]=='O')
{
winner=1;
cout <<game[2][0]<<" wins!!"<<endl;
}
else if(count>8)
cout<<"There is no winner";
}while(winner==0 && count<8);
return 0;
}