I am a beginner in c++ and trying to code Tic - Tac - Toe... i want to take input from the user in the form of numbers if player 1 hits a number say 1 replace it with X but it isn't working !!
#include < iostream >
using namespace std;
char player = 'X';
char matrix [3] [3] = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' ,'9'};
void Draw(){
for (int i=0 ; i<3 ; i++ ){
for (int j=0 ; j<3 ; j++ ){
cout << matrix [i][j] << " ";
}
cout << endl ;
}
}
void Input () {
char a;
cin >> a;
if ( a == 1 ) {
matrix [0] [0] = player; //player 1 turn print X from
// char player='X';
}
else if(a==2){
matrix[0][1]=player;
}
else if(a==3){
matrix[0][2]=player;
}
else if(a==4){
matrix[1][0]=player;
}
else if(a==5){
matrix[1][1]=player;
}
else if(a==6){
matrix[1][2]=player;
}
else if(a==7){
matrix[2][0]=player;
}
else if(a==8){
matrix[2][1]=player;
}
else if(a==9){
matrix[2][2]=player;
}
Output is 1 not X
can u please give me the answer!
many thanks.