Hi, I just finished coding a refined version of xoax.net's Tictactoe C++ program, but there is a bug in the program. When you finish the first round of the game it asks you if you want to replay or not, if you enter 'y' it clears the board and restarts, but for some reason it won't accept the inputs. Heres the code:
I debugged your code and found the problem in like 2 minutes. I would advice you to learn how to debug as it is as important as programming.
but for some reason it won't accept the inputs
It does accept the inputs actually, the problem that the board is restarting after each input, not allowing you to see them.
The reason being, after one round, if the user enters 'y' to play again, the variable cReplay will be equal to 'y'. So each iteration, since cReplay is still equal to 'y', this if statement will be true - if (cReplay == 'y') and clear the board.
So you basically have to reset cReplay in the end of the game. Which you try to do in the if statement I mentioned above. You correctly restart bGameOver and bTie, but fail to reset cReplay.
1 2 3 4 5 6 7 8 9 10
if (cReplay == 'y')
{
for (int iX = 0; iX <9; ++iX)
{
caBoard[iX] = iX+'1';
}
bGameOver = (false);
bTie = (false);
cReplay = 'y'; // you have to set cReplay to literally any other character and the game will work perfectly fine
}