Abdulg

GOTY

Mar 16th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include<stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     cout << "Hello and welcome to number guesser" << endl << "Please guess a number from 1 - 10" << endl;
  10.     srand(time(NULL));
  11.     int GeneratedNumber = rand () % 10 + 1;
  12.     int Input;
  13.  
  14.     for (int Lives = 3; Lives > 0; Lives--)
  15.     {
  16.         cout << "Your guess?" << endl << ">";
  17.         cin >> Input;
  18.  
  19.         if(Input == GeneratedNumber)
  20.         {
  21.             cout << endl << "You got it!" << endl;
  22.             Lives = 0;
  23.         }
  24.  
  25.         else if (Input < GeneratedNumber) cout << endl << "Too small!" << endl;
  26.         else cout << "Too big!" << endl;
  27.     }
  28.  
  29.     if (GeneratedNumber != Input) cout << "You died..." << endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment