Hi I am currently creating a naught's and crosses program for a college assignment and have come across an undeclared identifier error and I am not sure how to solve it. Below is my code.
#include "player.h"
int main()
{
Player Player1;
Player Player2;
Player1.Choose(0);
Player2.Choose(X);
cout << "The board is being drawn please wait..." << endl;
constint Rows = 3;
constint Columns = 3;
char Board[Rows][Columns] = { {'_', '_', '_' },
{'_', '_', '_' },
{'_', '_', '_' } };
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
cout << endl << endl;
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
int row;
do
{
cout << "Please enter the value of the row you would like to take ";
cin >> row;
}while (row != 0 && row != 1 && row != 2);
int column;
do
{
cout << "Please enter the value of the column you would like to take ";
cin >> column;
}while (column != 0 && column != 1 && column != 2);
Board [row][column] = 'X';
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
system("pause");
}
The error is pretty self explanitory. You're passing a variable named X to the Choose function, but you never defined any variable named X.
You probably meant to pass the literal character X and not a variable named X. So you forgot to put it in quotes:
Player2.Choose('X');
Similarly, the line above that probably should have been the literal 'O' character, and not zero (which is the null character that can't be graphically represented):