After the user enters the integers, they get a message about winning or losing. How do i keep i going ask if they want to play again. If they type yes keep going, if no stop. I am not sure why this isn't working Thanks
#include <iostream>
using namespace std;
int main()
{
bool program_continue = true;
char quit;
while (program_continue)
{
int i, j, k;
std::string exit_no("no");
std::string exit_yes("yes");
cout << "Please enter a number: ";
cin >> i;
cout << "Please enter a number: ";
cin >> j;
cout << "Please enter a number between " << i << " and " << j << ": ";
cin >> k;
if (k > i && k < j) ///if i < k < j
{
cout << "YOU WIN!" << endl;
}
else
{
cout << "YOU LOSE!" << endl;
}
cout << "Do you want to play again (yes or no)";
cin >> quit;
First: I switched the true and false around in the if statement. When entering yes the program would exit and when no was entered the program would continue.
Second: Changed char quit to string quit. Since you are using strings the program wasn't able to compare quit while it was a char.
Third: You didn't have #include <string> this will allow you to use strings.
#include <iostream>
#include <string> // Need to have this when using strings
usingnamespace std;
int main()
{
bool program_continue = true;
string quit;
while (program_continue)
{
int i, j, k;
std::string exit_no("no");
std::string exit_yes("yes");
cout << "Please enter a number: ";
cin >> i;
cout << "Please enter a number: ";
cin >> j;
cout << "Please enter a number between " << i << " and " << j << ": ";
cin >> k;
if (k > i && k < j) ///if i < k < j
{
cout << "YOU WIN!" << endl;
}
else
{
cout << "YOU LOSE!" << endl;
}
cout << "Do you want to play again (yes or no)";
cin >> quit;
if(exit_no.compare(quit) != 0)
{
program_continue = true;
}
else
{
program_continue = false;
}
}
return 0;
}