Looping a program

I'm working on a piece of code which will loop my entire program from a certain point within main:

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
  bool playAgain()
{
	char yesOrNo;
	
	cout << "Do you want to play again (y/n)? ";
	cin >> yesOrNo;
	
	if (yesOrNo == 'y')
		return true;
	else if (yesOrNo == 'n')
		return false;
	else
		while (yesOrNo != 'y' || yesOrNo != 'n')
		{
			cout << "Must enter y for yes, or n for no." << endl;
			cout << "Do you want to play again (y/n)";
			cin >> yesOrNo;
		}
}


int main()
{
	char madLibStory[256][32];

	readFile(madLibStory);
	
	do
	{
		readFile(madLibStory);
	} while (playAgain());
	
	return 0;
}


However, I'm having issues with this code. Certain variations will loop infinitely getting caught up each time at the first prompt (I didn't include the entire. Others will prompt to play again in the very beginning. This particular version runs it as I think it should run, but it will never prompt the user if they want to play again; which I think I understand why (the function isn't being called?)

What I need it to do is run the entire function and then prompt to play again. Can I get some direction on this? I've tried just about everything I can think of.

*PS: I apologize if someone saw a similar post a few days ago, I changed my program considerably [although I suppose this particular part isn't much different].
Last edited on
closed account (Dy7SLyTq)
change the || to &&
Ok, but that doesn't fix the issue I dont think.
1
2
3
4
5
6
7
8
9
10
11
while(yesOrNo != 'y' || yesOrNo != 'n')
		{
			cout << "Must enter y for yes, or n for no." << endl;
			cout << "Do you want to play again (y/n)";
			cin >> yesOrNo;
			//Check the new input..
			if (yesOrNo == 'y')
                		return true;
            		else if (yesOrNo == 'n')
                		return false;
		}
Topic archived. No new replies allowed.