Me and my partner have to create a Tic Tac Toe game for our project. I was wondering if anyone could look at the code for me and help me figure out the errors? Any help is appreciated
Check the brackets { }. For example, that elseif (playerAnswer == 'q') on line 53 is aligned with the if (playerAnswer == 'y') on line 27, but there's no closing } for the while loop started on line 29 before the else if. So the elseif is in the while and the compiler can't match it to a preceding if.
Okay, so I fixed all the braces, and I also made it so there were no errors, yet when I compile it just repeats the asking for the player names, here is the updated code:
It seems like that while (playerAnswer != 'q') could be pulled outside the if statement to control the overall game.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
while user wants to play a game
get player names
while no one has won and the board is not full
display the board
decide whose turn it is
get player move
if player move valid
mark square with player symbol
otherwise
invalid move message
if someone won
display winner message
otherwise (draw)
display draw message
ask if user wants to play another game
One last question (I think) I fixed what you said, and the game works for 2 player, but it does not work for our simple AI, and after a game is finished it just goes back to asking for player name. Here is the updated code.
From what I see, if the player enters "AI" for the second player, there's a message confirming that at line 43. But the code in the loop still asks each player to make a move. If they've chosen "AI" as the second player, are you supposed to have the computer analyze the choices on the board and select an empty spot?
At the end of the game, you can ask the player if they want to play again, so if they enter 'n', the loop won't restart and ask for player names.