Hi..
I don't know how to do the draw condition & error checking on the following tic tac toe codes,
can anyone help me to complete this with elaborations and explanations please.. thanks
#include<iostream>
using namespace std;
char box[9]={'1','2','3','4','5','6','7','8','9'};
void drawboard()
{
cout<< box[0]<<" | "<<box[1]<<" | "<<box[2]<<endl;
cout<< "---------"<<endl;
cout<< box[3]<<" | "<<box[4]<<" | "<< box[5]<< endl;
cout<< box[6]<<" | "<<box[7]<<" | "<<box[8]<<endl;
}
int winning(char f[])
{
if(box[0]==box[1] && box[2]==box[0])
return 1;
else if(box[3]==box[4] && box[5]==box[3])
return 1;
else if(box[6]==box[7] && box[8]==box[6])
return 1;
else if(box[0]==box[3] && box[6]==box[0])
return 1;
else if(box[1]==box[4] && box[7]==box[1])
return 1;
else if(box[2]==box[5] && box[8]==box[2])
return 1;
else if(box[0]==box[4] && box[8]==box[0])
return 1;
else if(box[2]==box[4] && box[6]==box[2])
return 1;
else
return 0;
}
int main()
{
char c[2]={'x','o'};
int move;
int i=0;
int player=2;
for (i=0;i<=9;i++)
{
if (i<9&&winning(box)==0)
{
drawboard();
if(player==2)
player=1;
else
player=2;
cout<<"player"<<player<<" please select an available number"<<endl;
cin>>move;
box[move-1]=c[player-1];
if (winning(box)==1)
cout<<"congratulations dear player "<<player<<" "<<"you are the winner :)"<<endl;
return 0;
}
}
}