#include <iostream>
#include <stdio.h>
#include <string>
usingnamespace std;
int main()
{
int start ;
int finish;
bool PlayAgain = 0;
char PlayAgainAnswer;
do {
do {
cout << "what number would you like the computer to count to?: ";
cin >> finish;
cout << "what number would you like the computer to start at?: ";
cin >> start;
if (start >= finish)
cout << "The number you start at has to be smaller then the number your counting to. \n";
} while (start >= finish);
while (start <= finish){
cout << start << endl;
start = start + 1;
}
do {
cout << "Do you wanna play again? (y/n): ";
cin >> PlayAgainAnswer;
} while (PlayAgainAnswer != 'y' || 'n' || 'Y ' || 'N');
if (PlayAgainAnswer == 'y' || 'Y')
bool PlayAgain = 1;
if (PlayAgainAnswer == 'n' || 'N')
bool PlayAgain = 0;
} while (PlayAgain == 1);
return 0;
}
when i run the program it always asks me "Do you wanna play again? (y/n):" no matter what i type in
In addition to thepedestrian's solutions in the other thread:
1) Change the 'Y ' (space) on line 33 to 'Y' (no space).
2) Get rid of "bool" in front of PlayAgain on lines 36 and 39... otherwise, you're defining two new objects, limited in scope to each if block, not referencing the original variable.