Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main() {
- bool loop = false;
- char play_again = ' ';
- int guess = 0;
- srand( time(NULL) );
- int the_number = rand() % 101;
- cout << "I will think of a number between 1 and 100, and you have to guess it. Go ahead and make your first guess.\n\n";
- loop=true;
- while(cin>>guess && loop==true) {
- if(guess>the_number) {
- cout << "Too high! Think lower.\n";
- }
- if(guess<the_number) {
- cout << "Too low! Think higher.\n";
- }
- if(guess==the_number) {
- cout << "Winrar!\nWould you like to play again (y/n)?\n\n";
- cin >> play_again;
- if(play_again=='y') {
- loop=true;
- cout << "\n\nMake your first guess (between 1-100):\n\n";
- the_number = rand() % 101;
- }
- if(play_again=='n') {
- loop=false;
- return 0;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment