//************************************************************************************
	//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);
                }
	}

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

Edited 6 Years Ago by griswolf: n/a

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

Edited 6 Years Ago by abhimanipal: n/a

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.

This article has been dead for over six months. Start a new discussion instead.