I am trying to create a simple tic-tac-toe game for an assignment. I believe there is a problem with my get_move function. After the user picks the row and column, it ignores it and places their letter at (0,0). When it switches to the other player it does the same thing and erases the other players output. All the functions seen have been previously defined. The program doesn't return an error. It runs; it just won't do what it is supposed too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void get_move(char board[3][3], char player)
{
{
int row, column;
while (square_occupied(board, row, column))
{ cout << "ERROR: You attempted to put a mark in an occupied square. Please, try again.";
get_row(board, player);
get_column(board, player); }
board[row][column] = player;
cout << board[row][column];
if (player == 'X')
player = 'O';
else
player = 'X';
}
I am not very familiar with how most people indent their code.
The exact specifics are up for debate; size of indent, location of opening and closing brackets, spaces vs. tabs, etc.
But a consistent style makes your problem obvious:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void get_move(char board[3][3], char player)
{
{
int row, column;
while (square_occupied(board, row, column))
{
cout << "ERROR: You attempted to put a mark in an occupied square. Please, try again.";
get_row(board, player);
get_column(board, player);
}
board[row][column] = player;
cout << board[row][column];
if (player == 'X')
player = 'O';
else
player = 'X';
}
(No closing bracket after line 17, or an extra opening bracket at line 3. Take your pick. I'd go with extra opening bracket.)