TIC TAC TOE GAME using C++
One player will input 'O' and the other will input 'X' to fill the grid as above in order to get 3 in a row to win the game.
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
{
char x,y,z,w;
char arr[3][3];
cout<<"Start!"<<endl;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
cin>>arr[i][j];
}
for(int l=0;l<3;l++)
{
x=arr[l][0];
z=arr[0][l];
if(x==arr[l][1])
{
y=arr[l][2];
if(y==x)
{
cout<<y<<" WINS"<< endl;
}
}
if(z==arr[1][l])
{
w=arr[2][l];
if(z==w)
{
cout<<z<<" WINS"<<endl;
}
}
}
if (arr[0][0]==arr[1][1]||arr[0][2]==arr[1][1])
{
if( arr[1][1]==arr[2][2]||arr[1][1]==arr[2][0])
cout<<arr[1][1]<<" WINS"<<endl;
}
return 0;
}
OUTPUT:
1.After running the program,instruction is given to start the program.
2.Players can start inputting values as below.
3.When all 9 values are inputted, the result will be given.
Comments
Post a Comment