It's the same problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
cout << "You will start with 200 dollars " << endl;
cout << "Do you want to play with the One Armed Bandit? ";
cin >> answer;
if (answer != 'n' || answer != 'y')
getyorn();
if (getyorn() == 'n')
{
cout << endl << "Thank you for playing. Good luck. ";
}
while (getyorn() == 'y')
{
getbet(bet);
pullhandle();
cout << endl << "Do you want to play again? ";
getyorn();
if (getyorn() == 'n')
cout << endl << "Thank you for playing. Good luck. ";
}
|
Every time you call getyorn(), it waits for the user to enter y or n.
You are calling it several times.
First, you cin >> answer. This is the first 'y'.
Then, you call it a second time here: if( answer != 'y' || answer != 'n' ) getyorn();
(Draw out the truth table to convince yourself that your if() clause is always true.
Then, you call it a third time here: if( getyorn() == 'n' ).
Then, you call it a fourth time here: while( getyorn() == 'y' ).
This makes up the four times you have to enter 'y' to get your program to continue.
To fix this issue, as with the other issue I mentioned, you only want to call the function
once and save off the returned value. For example:
1 2 3 4
|
char answer = getyorn();
if( answer == 'n' ) {
// ...
}
|