Advertisement
Felanpro

Random Number Generator With (rand function!

Nov 22nd, 2015
122
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. using namespace std;
  3.  
  4. int main()
  5. {
  6.     start:
  7.     int randomNumber = (rand() % 101);
  8.     int guess;
  9.    
  10.     cout << "Number guessing game" << endl;
  11.     cout << "********************" << endl;
  12.    
  13.     cout << "The random number has been generated; it's between 1-100" << endl;
  14.     play:
  15.     cout << "Guess: ";
  16.     cin >> guess;
  17.    
  18.     if(guess == randomNumber)
  19.     {
  20.              cout << "Correct, play again.." << endl;
  21.              system("pause");
  22.              goto start;
  23.              }
  24.              else if(guess < randomNumber)
  25.              {
  26.                   cout << "Wrong, the random number is greater" << endl;
  27.                   goto play;
  28.                   }
  29.                   else if(guess > randomNumber)
  30.                   {
  31.                        cout << "Wrong, the random number is less" << endl;
  32.                        goto play;
  33.                    }
  34.    
  35.    
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement