Sign in to follow this  

Why isnt this working?

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have code for an already finished homework assignment that im adding some embellishments to, namely some extra error correction. Its a tic tac toe game and I discovered that you can accidentally rewrite over someone elses X or O. I thought the error correction would be easy, boy was I wrong. Here is the error correcting method:
[source lang = "cpp"]
void TicTacToe::spaceCheck(int row, int column, bool &spaceAvailable)
{
	if(theBoard[row][column] == ' ')
	{
		spaceAvailable = true;
	}

	else
	{
		cout<<"\nThat space is already taken!\n";
		spaceAvailable = false;
	}
}

That is the method that checks to see if the space is available. Here is the method that calls it.
[source lang = "cpp"]
void TicTacToe::playOneGame(void)
{
	bool spaceAvailable = NULL;
	char currentPlayer  = 'O';
	char theWinner      = ' ';
	const int MaxMoves  = 9;
	int row             = 0;
	int column          = 0;
	int numberOfMoves   = 0;  //keeps track of number of moves, max is 9

	do{
		switchPlayer(currentPlayer);
		showBoard();
		do
		{
			cout<<"\nPlayer "<<currentPlayer<<endl;
			playerInput(row, "row");
			playerInput(column, "column");
			spaceCheck(row,column, spaceAvailable);
			cout<<endl;
		}while(spaceAvailable != true);

		postMove(row-1,column-1,currentPlayer); //post the move to the board
		theWinner = determineWinner(); //see if anyone won the game
		numberOfMoves++; //keep track of the number of moves
	}while((theWinner == 'D') && (numberOfMoves < MaxMoves));

	showBoard(); //shows the ending board

I dont understand why my spaceCheck method isnt catching the error. It looks correct to me but obviously it isnt : /

Share this post


Link to post
Share on other sites

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this