Hi guys I'm new to C++ Programming and I am having trouble in making my Guessing game code replay. I am suppose to give the user that is playing my game the opportunity to play again with options of 'Yes' and 'No' and if Yes then the game starts up again and if No then the game tells the user bye and quits.
"Do you want to play again? (y/n)"
Please Help if possible thanks. ^^
-----------------------------------------
[code=cpp]
#include <iostream>
using namespace std;
int main()
{
cout << "\t\tWelcom e to the Number Guessing Game!\n\n";
cout << "Think of a number between 1 and 1000 and I'll try to guess it.\n";
cout << "After guess, respond with 1 for higher, 2 for lower, or 3 for correct";
int tries = 0;
int low = 0;
int high = 1001;
char response = 1;
do
{
int guess = (low + high) / 2;
cout << "\nMy guess is " << guess << endl;
tries += 1;
cout << "Is your number (1)higher, (2) lower or am I correct?(3): ";
cin >> response;
switch (response)
{
case '1':
low = guess;
break;
case '2':
high = guess;
break;
case '3':
cout << "Yeah! I guessed your number in only " << tries << " tries.";
break;
default:
cout << "Uh, error. You made an illegal choice. " << response << endl;
}
} while (response != '3');
system ("pause");
return 0;
}[/code]
"Do you want to play again? (y/n)"
Please Help if possible thanks. ^^
-----------------------------------------
[code=cpp]
#include <iostream>
using namespace std;
int main()
{
cout << "\t\tWelcom e to the Number Guessing Game!\n\n";
cout << "Think of a number between 1 and 1000 and I'll try to guess it.\n";
cout << "After guess, respond with 1 for higher, 2 for lower, or 3 for correct";
int tries = 0;
int low = 0;
int high = 1001;
char response = 1;
do
{
int guess = (low + high) / 2;
cout << "\nMy guess is " << guess << endl;
tries += 1;
cout << "Is your number (1)higher, (2) lower or am I correct?(3): ";
cin >> response;
switch (response)
{
case '1':
low = guess;
break;
case '2':
high = guess;
break;
case '3':
cout << "Yeah! I guessed your number in only " << tries << " tries.";
break;
default:
cout << "Uh, error. You made an illegal choice. " << response << endl;
}
} while (response != '3');
system ("pause");
return 0;
}[/code]
Comment