0

hi, i have the following code for tic tac toe game Human vs. Computer, it runs without problem but when i prompt for entering X or O, it gives an error, can someone help, appreciate the answer.

here's my code:

```
#include <iostream>
#include<conio.h>
#include<process.h>
using std::cout;
using std::cin;
char matrix[3][3];
char check(void);
void init_matrix(void);
void get_player_move(void);
void get_computer_move(void);
void disp_matrix(void);
int main()
{
char done;
cout<<"\n'TIC-TAT-TOE'\t Human Vs.Computer\n";
done=' ';
init_matrix();
do{
disp_matrix();
get_player_move();
done=check();
if(done!=' ')
break;
get_player_move();
done=check();
}while(done==' ');
if(done=='X')
cout<<"\nYOU WON";
else
cout<<"I WON";
disp_matrix();
return 0;
}
void init_matrix(void)
{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
matrix[i][j]=' ';
}
void get_player_move(void)
{
int x,y;
cout<<"\nEnter X,Y coordinates for your move: ";
cin>>x>>y;
x--;
y--;
if (matrix[x][y]!='you have choosen the worng letter')
{
cout<<"\nInvalid move,TRY again";
get_player_move();
}
else matrix[x][y]='X';
}
void get_computer_move(void)
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
if(matrix[i][j]==' ')
break;
if (matrix[i][j]==' ')
break;
}
if(i*j==9)
{
cout<<"\nDRAW\n";
exit(0);
}
else
matrix[i][j]='o';
}
void disp_matrix(void)
{
int t;
for(t=0;t<3;t++)
{
cout<<matrix[t][0]<<matrix[t][1]<<matrix;
if(t!=2)
cout<<"\n---|---|---\n";
}
cout<<"\n";
}
char check(void)
{
int i;
for(i=0;i<3;i++)
if (matrix[i][0]==matrix[i][1]&&matrix[i][0])
return matrix[i][0];
for(i=0;i<3;i++)
if (matrix[0][i]==matrix[1][i]&&matrix[0][i])
return matrix[0][i];
if (matrix[0][0]==matrix[1][1]&&matrix[1][1])
return matrix[0][0];
if (matrix[0][2]==matrix[1][1]&&matrix[1][1])
return matrix[0][2];
return ' ';
}
```

*Edited 6 Years Ago by phpangel*: n/a