Advertisement
Felanpro

Random Generator Guessing Game (Refresh))

Nov 21st, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. //Program uses time function to seed random number generator
  2. //and then generates random number
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     srand((unsigned)time(NULL));
  11.     int d = rand()%12;
  12.     cout << d;
  13.     system("cls");
  14.    
  15.     play:
  16.     int guess;
  17.     cout << "Guess the random generated number: ";
  18.     cin >> guess;
  19.    
  20.     if(guess == d)
  21.     {
  22.              cout << "You were right!" << d << "was right" << endl;
  23.              
  24.              }
  25.              else
  26.              {
  27.                  cout << "that was wrong try again" << endl;
  28.                  system("pause");
  29.                  goto play;
  30.                  }
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement