#include<iostream> using namespace std; char mat[3][3]; void matrix(); int main(
ID: 3611019 • Letter: #
Question
#include<iostream>
using namespace std;
char mat[3][3];
void matrix();
int main()
{int i,j;
for(i=0;j<3;i++)
for(j=0;j<3;j++)
mat[i][j]=' ';
matrix ();
int turns=1; //totalof 9 turns will be there
int row=0, column=0;
char c;
while(turns <=9)
{
if((turns%2) !=0)
{
cout<<"X's turn - Enter your move "<<"Row (1-3) andcolumn (1-3) seperated by a space: "<<endl;
c='X';
}
else
{
cout<<"O's turn - Enter your move "<<"Row (1-3) andcolumn (1-3) seperated by a space: "<<endl;
c='O';
}
cin>>row;
cin>>column;
if( (row <4) && (column <4))
{
if((mat[row-1][column-1] !='X') && (mat[row-1][column-1] !='O'))
{
mat[row-1][column-1]=c;
matrix();
turns++;
}
else
{
cout<<"This postion has already been occupied by:"<<mat[row-1][column-1]<<endl;
matrix();
}
}
else
{
cout<<"Entered wrong number"<<endl;
}
}
return 0;
}
void matrix()
{int i;
for(i=0; i<3; i++)
{cout<<" "<< mat[i][0]<<" | "<< mat[i][1] << " | "<< mat[i][2];
if(i!=2)
cout<<" --- --- --- ";
}
cout<<endl;
return;
}
Explanation / Answer
please rate - thanks use function check from here #include char mat[3][3]; void check(); void init(); void human(char); void print(); int main() { char done; done = ' '; init(); do {print(); human('X'); check(); print(); human('O'); check(); } while(done== ' '); } void init() {int i, j; for(i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.