I have the code to ask a user to enter 3 numbers then they win or lose. How do I add the code to ask them if they want to continue and if they say yes then start over asking for new integers? Thanks!
#include <iostream>
using namespace std;
int main()
{
int i,j,k;
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;
}
return 0;
}
Thanks this is great rafae11. The only thing missing is if they don't want to continue. Can it have something like enter no if you don't want to continue? 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;