daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest May 16th, 2018 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     bool loop = false;
  9.     char play_again = ' ';
  10.     int guess = 0;
  11.     srand( time(NULL) );
  12.     int the_number = rand() % 101;
  13.     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";
  14.     loop=true;
  15.     while(cin>>guess && loop==true) {
  16.         if(guess>the_number) {
  17.             cout << "Too high! Think lower.\n";
  18.         }
  19.         if(guess<the_number) {
  20.             cout << "Too low! Think higher.\n";
  21.         }
  22.         if(guess==the_number) {
  23.             cout << "Winrar!\nWould you like to play again (y/n)?\n\n";
  24.             cin >> play_again;
  25.             if(play_again=='y') {
  26.                 loop=true;
  27.                 cout << "\n\nMake your first guess (between 1-100):\n\n";
  28.                 the_number = rand() % 101;
  29.             }
  30.             if(play_again=='n') {
  31.                 loop=false;
  32.                 return 0;
  33.             }
  34.         }
  35.     }
  36.  
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top