I'm just calling a function with a 2D array as an argument. I don't see why it's telling me there's no function to call, I can see the function.
Here's the prototype, at the beginning of my code:
void displayBoard(int [][COLS], int);
here's the function calling displayBoard and the displayBoard function:
void playerTurn()
{
char board[ROWS][COLS] = {{'*', '*', '*'}, {'*', '*', '*'}, {'*', '*', '*'}};
char row, col;
displayBoard(board, ROWS);
cout << "Player X's Turn.\nEnter a row and a column to place an X.\nRow: ";
cin >> row;
cout << "\nColumn: ";
cin >> col;
//clear screen
//edit contents of 2D array
displayBoard(board, ROWS);
cout << "Player O's Turn.\nEnter a row and a column to place an X.\nRow: ";
cin >> row;
cout << "\nColumn: ";
cin >> col;
//Validate each user's move (make sure there isn't an x or o already there
//Ask for a re-input is validation fails
}
void displayBoard(const char board[][COLS], int ROWS)
{
cout << setw(14) << "Columns" << endl;
cout << setw(14) << "1 2 3 " << endl;
cout << "Row 1: " << board[0][0] << " " << board[0][1] << " " << board[0][2] << endl;
cout << "Row 2: " << board[1][0] << " " << board[1][1] << " " << board[1][2] << endl;
cout << "Row 3: " << board[2][0] << " " << board[2][1] << " " << board[2][2] << endl;
cout << endl;
}
It gives me the error at both calls in the playerTurn function. I can't figure out what I'm doing wrong.
You have declared before you function definitions
void displayBoard(int [][COLS], int);
Then in playerTurn()
you call
displayBoard(board, ROWS);
Here board
is a char board[ROWS][COLS]
so the compiler looks to see if it has seen a function declared or defined named displayBoard
that takes those parameters. Since the compiler has not seen it it will issue an error.
To fix this you either need to change the decleration to
void displayBoard(const char board[][COLS], int ROWS);
Or you can just change the order of the functions and have playerTurn()
defined before displayBoard()