//************************************************************************************
	//function playagain();
	//parameters char cAns
	//resets game variables and board or exits game
	//************************************************************************************
	void playagain(char cAns)
	{
		cout<<"would you like to play again?(y/n)"<<endl;//function call depending of the choice of the player
		cin>>cAns;//sts value to variable
		do
		{

			iTotalMoves=0;//resets # of moves
			ResetBoard();//resets game array
			cPlayerSymbol='a';//resets game char (so that function will ask the player X or O again)
			symbol(); // ask the player's symbol then calls the game function

		}
		while(cAns=='y' || 'Y');//but no matter what I type (as long as it's not y or Y, it loops into the game again
		return(0);
	}

it's not exiting, and I know I coded this this way before.

or should I do it this way

//************************************************************************************
	//function playagain();
	//parameters char cAns
	//resets game variables and board or exits game
	//************************************************************************************
	void playagain(char cAns)
	{
		cout<<"would you like to play again?(y/n)"<<endl;//function call depending of the choice of the player
		cin>>cAns;//sts value to variable
		if(cAns=='y' || 'Y')
		{

			iTotalMoves=0;//resets # of moves
			ResetBoard();//resets game array
			cPlayerSymbol='a';//resets game char (so that function will ask the player X or O again)
			symbol(); // ask the player's symbol then calls the game function

		}
		else
                {
		        return(0);
                }
	}

Recommended Answers

All 4 Replies

while(cAns=='y' || 'Y') This says: While (cAns == 'y') || 'Y'
.. which is always either true or 'Y' .. which is always true.

You probably want to say

while(cAns=='y'||cAns=='Y')
{}

Also I think the expansion of while(cAns=='y'||'Y') should be while((cAns=='y')||'Y') which will always be true

not sure if this will help but the Do while loop always executes at least once.

void playagain(char cAns)
	{
		cout<<"would you like to play again?(y/n)"<<endl;//function call depending of the choice of the player
		cin>>cAns;//sets value to variable

		if (cAns=='n'|| cAns=='N')
		{
			exit(0);
		}		



		if(cAns=='y' || cAns== 'Y')
		{

			iTotalMoves=0;//resets # of moves
			ResetBoard();//resets game array
			cPlayerSymbol='a';//resets game char (so that function will ask the player X or O again)
			symbol(); // ask the player's symbol then calls the game function
		}



	}

Once I reversed it, it worked. I dunno really why either, but hell it did. I will keep in mind the do while loops, (love those)
Hey lets find more ways to make exit functions. I already turned in the work, it's finished but this is enjoyable.

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.