I have this code and I am having trouble figuring how to make it run without any errors, can anybody give me some pointers on how to fix it

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

class TicTacToe
{
private:
	char theBoard [3][3];
public:
	TicTacToe(void);
	void playOneGame(void);
	void switchPlayer(char &);
	void showBoard(void);
	void postMove(int, int, char);
	char determineWinner(void);
};

int main (void)
{
	//test the class by playing one game
	TicTacToe Game1;
	Game1.playOneGame();
	return 0;
}

void TicTacToe::playOneGame(void)
{
	//start a game and play until someone wins or a draw occurs...
	const int MaxMoves = 9;
	char currentPlayer = 'O';
	int row = 0;
	int clmn = 0;
	char theWinner = ' ';
	int nmbrOfMoves = 0; //keep track of the number of moves max is 9
	do 
	{
		switchPlayer(currentPlayer); //change player from x to o or vice versa                
		showBoard();           
		cout << "\n\nPlayer " << currentPlayer << endl; //get the players move 
		cout << "enter your row: ";
		cin >> row;
		cout << "enter your column: ";
		cin >> clmn; 
		postMove(row, clmn, currentPlayer); //post the move to the board      
		theWinner = determineWinner();  //see if anyone won the game
		nmbrOfMoves++;  //keep track of the number of moves

	}
	while((theWinner == 'D') && (nmbrOfMoves < MaxMoves));
	showBoard(); //show the ending board

	if(theWinner != 'D')  //declare a winner
	{
		cout << "\n\nThe Winner is player " << theWinner;
	}
	else
	{
		cout << "\n\nThe Game was a Draw";
	}
}

TicTacToe::TicTacToe(void)
{
	char theBoard [3][3];
	for(int i = 0; i< size; i++)
	{	for(int j = 0; j< size; j++)
		{
			theBoard[i][j] = ' ';
		}
	}
}

void TicTacToe::switchPlayer(char &currentPlayer)
{
         //switches the current player
	Start
	if(currentPlayer = 'x' || currentPlayer = 'X')
	{
		currentPlayer = 'X'
	}
	else
	{
		if(currentPlayer = 'o' || currentPlayer = 'O')
		{
			currentPlayer = 'O'
		}
	}
}

void TicTacToe::showBoard(void)
{
	//displays the board
	for(int i = 0; i< size; i++)
	{
		for(int j = 0; j< size; j++)
			cout << " [ "<< theBoard[i][j] << " ] \n";
		cout << endl;
	}
}

void TicTacToe::postMove(int row, int col, char value)
{
       //gets the users move and posts it to the board

}

char TicTacToe::determineWinner(void)
{
	//analyzes the board to see if there is a winner
	//returns a X, O indicating the winner
	//if the game is a draw then D is returned

	//check the rows
	for (int i = 0; i < 3; i++)
	{
		if (theBoard[i][0] == theBoard[i][1] && theBoard[i][1] == theBoard[i][2] && theBoard[i][0] != ' ')
		{
			return theBoard[i][0];
		}
	}
	//check the clmns
	for (int i = 0; i < 3; i++)
	{
		if (theBoard[0][i] == theBoard[1][i] && theBoard[1][i] == theBoard[2][i] && theBoard[0][i] != ' ')
		{
			return theBoard[0][i];
		}
	}
	//check the diagonals
	if (theBoard[0][0] == theBoard[1][1] && theBoard[1][1] == theBoard[2][2] && theBoard[0][0] != ' ') 
	{
		return theBoard[0][0];
	}
	if (theBoard[2][0] == theBoard[1][1] && theBoard[1][1] == theBoard[0][2] && theBoard[2][0] != ' ') 
	{
		return theBoard[2][0];
	}
	return 'D';
}

Here are the error codes
Error 1 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 2 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 3 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 4 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 5 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 6 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 7 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 8 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 9 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 10 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 11 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37
Error 12 error C2065: '           ' : undeclared identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 38
Error 13 error C2146: syntax error : missing ';' before identifier 'cout' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 38
Error 14 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 42
Error 15 error C2065: ' ' : undeclared identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 43
Error 16 error C2146: syntax error : missing ';' before identifier 'postMove' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 43
Error 17 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 44
Error 18 error C2146: syntax error : missing ';' before identifier 'nmbrOfMoves' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 45
Error 19 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 45
Error 20 error C2143: syntax error : missing ';' before '}' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 47
Error 21 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 51
Error 22 error C2143: syntax error : missing ';' before '{' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 52
Error 23 error C2181: illegal else without matching if \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 55
Error 24 error C2065: 'size' : undeclared identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 64
Error 25 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 26 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 27 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 28 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 29 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 30 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 31 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 32 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 74
Error 33 error C2065: '        ' : undeclared identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 76
Error 34 error C2146: syntax error : missing ';' before identifier 'Start' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 76
Error 35 error C2065: 'Start' : undeclared identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 76
Error 36 error C2143: syntax error : missing ';' before 'if' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 76
Warning 37 warning C4305: '=' : truncation from 'char' to 'bool' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 76
Error 38 error C2106: '=' : left operand must be l-value \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 76
Error 39 error C2143: syntax error : missing ';' before '}' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 79
Warning 40 warning C4305: '=' : truncation from 'char' to 'bool' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 82
Error 41 error C2106: '=' : left operand must be l-value \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 82
Error 42 error C2143: syntax error : missing ';' before '}' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 85
Error 43 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 102
Error 44 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 102
Error 45 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 102
Error 46 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 102
Error 47 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 102
Error 48 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 102
Error 49 error C2065: '      ' : undeclared identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 104
Error 50 error C2143: syntax error : missing ';' before '}' \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 104

Recommended Answers

All 4 Replies

line 66 of the code you posted: variable size has not been declared

line 77: what is Start ?

line 78: you need to use == boolean operator, not = assignment operator

there is quite a few problems trying to get this to compile.

did you write the entire program then try to compile it or did you compile bit-by-bit as you added them. Its a lot easier to create a program in parts.

maybe create the board first then get the constructor methods to work correctly, and then add components.

heres what gcc says about it, i hope it helps.

In constructor `TicTacToe::TicTacToe()': (line 66)
error: `size' was not declared in this scope
In member function `void TicTacToe::switchPlayer(char&)':
`Start' was not declared in this scope (line 78)
expected `;' before "if" (line 78)

things like this are missing semi colon

if(currentPlayer = 'x' || currentPlayer = 'X')
	{
		currentPlayer = 'X'
	}

line 66 of the code you posted: variable size has not been declared

line 77: what is Start ?

line 78: you need to use == boolean operator, not = assignment operator

Sorry, "Start" is my error, they gave me this whole code to fix and some parts they don't even explain what you need to do. Before posting this I had over 102 errors and now it's down to these.

The vast majority of these errors:

Error 1 error C3872: '0xa0': this character is not allowed in an identifier \\ilabss\home$\D03279277\Documents\Visual Studio 2005\Projects\Lab6Ex2\Lab6Ex2\Lab6Ex2.cpp 37

have nothing to do with the code you posted. I just copied and pasted into Code Blocks and didn't get any of the '0x0a' errors. You have some control character in there or there's a Unicode character or something. 0xa0 is 160, which is above 127, so it's not even ASCII. So the vast majority of your errors aren't coding errors. You have a project etting wrong or something didn't transfer over in your post or you aren't posting everything or something else. The errors also don't match the line numbers posted.

So first thing to do is get rid of all of those 0xa0 errors and get it down to the REAL errors. Then you can start debugging.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.