Hello,
I'm attempting to write a TicTacToe program for class and need some help with arrays. We have to write a program that will allow two users to play tic-tac-toe. The program needs to have turns alternately from player X and player O.
I have defined the board as char board[9]. The real problem is that in my loop that I have set up it's not giving me a chance to input each player's positions. I get a compilation error saying:
"Error E2377 lab4.cpp 31: If statement missing ) in function main()"
I've double and triple check my closed parenthesis and it seems to be correct, yet I have been staring at the screen for a while and it might need a fresh set of eyes.
Also, I dont have to draw a board of anything, just display it like so:
1 2 3
4 5 6
7 8 9
Players then choose the position they would like and it holds and marks the value for them. I haven't started with the postion, but would like advice on how to do so. I know that you will have to start the sequence with 0 and work up to 8 instead of 1-9.
Any direction or advice would be most welcomed and appreciated.
Here's what I have so far.
I'm attempting to write a TicTacToe program for class and need some help with arrays. We have to write a program that will allow two users to play tic-tac-toe. The program needs to have turns alternately from player X and player O.
I have defined the board as char board[9]. The real problem is that in my loop that I have set up it's not giving me a chance to input each player's positions. I get a compilation error saying:
"Error E2377 lab4.cpp 31: If statement missing ) in function main()"
I've double and triple check my closed parenthesis and it seems to be correct, yet I have been staring at the screen for a while and it might need a fresh set of eyes.
Also, I dont have to draw a board of anything, just display it like so:
1 2 3
4 5 6
7 8 9
Players then choose the position they would like and it holds and marks the value for them. I haven't started with the postion, but would like advice on how to do so. I know that you will have to start the sequence with 0 and work up to 8 instead of 1-9.
Any direction or advice would be most welcomed and appreciated.
Here's what I have so far.
Code:
#include <iostream>
using namespace std;
int main()
{
int Xpos, Opos, turn;
char board[9];
cout << "\nPlease enter a number corresponding to the board\n"
<< "to mark your spot. 3 in a row wins the game.\n";
cout << " Good Luck! \n\n";
cout << "\n1 2 3\n"
<< "4 5 6\n"
<< "7 8 9\n";
for (int turn = 1; turn < 10; turn++) //checks turn of player
{
do
{
if (turn !(% 2) == 0) //*heres where i get the error*
{ cout << "Player X, your move.\n"
cin >> board[Xpos]; //Player X input
}
else
{ cout << "Player O, your move\n"
<< board[Xpos] << endl; //Updated board
cin >> board[Opos]; //Player O input
cout << board[Opos]; //Updated board
}
}
while (turn < 10);
}
}
Comment