Advertisement
Felanpro

Number Guessing Game (With tries)

Nov 22nd, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.      srand((unsigned)time(NULL));
  9.     int randomNumber = rand() % 101;
  10.     int tries, guess = 0;
  11.    
  12.     do
  13.     {
  14.             cout << "Try to get the random number." << endl;
  15.             cin >> guess;
  16.             tries++;
  17.            
  18.             if(guess > randomNumber)
  19.             {
  20.                      cout << "Too high!" << endl;
  21.                      }
  22.                      else if(guess < randomNumber)
  23.                      {
  24.                           cout << "Too low!" << endl;
  25.                       }
  26.                       else if(guess == randomNumber)
  27.                       {
  28.                            cout << "Correct, you made it in " << tries << " tries." << endl;
  29.                            system("pause");
  30.                        }
  31.            
  32.             }while(guess != randomNumber);
  33.    
  34.     return 0;  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement