Naught's and Croses

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "player.h" 


int main()
{
	Player Player1;
	Player Player2;

	Player1.Choose(0);
		Player2.Choose(X);

		cout << "The board is being drawn please wait..." << endl;

		const int Rows = 3;
		const int 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");
}


This is the player.h header file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>

using namespace std;

class Player
{
private:
	char NorX;

public:

	int Choose(char InitialValue)
	{
		NorX = InitialValue;
	}

};


It is the Player2.Choose(X) on line 10 that is causing this error. Any help would be most appreciated.
Player2.Choose('X');

You need the single quotes for a char, otherwise the compiler thinks X is a variable.

HTH
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):

 
Player1.Choose('O');



EDIT: ninja'd!
Last edited on
Either
Player2.Choose('X');
or
1
2
const char X = 'X';
Player2.Choose(X);


And similarly for player 1.
Thank you very much
Topic archived. No new replies allowed.