I am making a tic tac toe board game and I need the user to enter any position between 1 to 9 then type in X or O. Some conditions I need include is that I want to restrict the user to enter any number greater than 9 and do not enter any character either than 'X' or 'O'. The problem I encounter is that it doesn't follow the conditional statement. Any help would be appreciated.
void CreateBoard(int m, int n, char board[][n])
{
int i, j, position;
char one;
char two;
char temp;
char xORo;
int count = 0;
int end;
do {
printf("Enter the number of the cell you want to insert X or O or enter -1 to exit: \n");
scanf("%d", &position);
printf("Type X or O: \n");
scanf(" %c", &xORo);
if(position < 0){
break;
}
if((position > 9) && xORo != ('X') && ('O'))
{
continue;
}
else if((position > 0 || position < 9) && xORo == ('X') && ('O'))
{
switch(position)
{
case 1: temp = xORo;
xORo = board[0][0];
board[0][0] = temp;
break;
case 2: temp = xORo;
xORo = board[0][1];
board[0][1] = temp;
break;
case 3: temp = xORo;
xORo = board[0][2];
board[0][2] = temp;
break;
case 4: temp = xORo;
xORo = board[1][0];
board[1][0] = temp;
break;
case 5: temp = xORo;
xORo = board[1][1];
board[1][1] = temp;
break;
case 6: temp = xORo;
xORo = board[1][2];
board[1][2] = temp;
break;
case 7: temp = xORo;
xORo = board[2][0];
board[2][0] = temp;
break;
case 8: temp = xORo;
xORo = board[2][1];
board[2][1] = temp;
break;
case 9: temp = xORo;
xORo = board[2][2];
board[2][2] = temp;
break;
}
PrintBoard(3, 3, board);
}
}while(position != -1);
}
Aucun commentaire:
Enregistrer un commentaire