Advertisement
Felanpro

Number Guessing Game

Nov 2nd, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int g, n;
  10.    
  11.     play:
  12.     srand (time(NULL));
  13.     n = rand() % 20 + 1;
  14.     system("cls");
  15.    
  16.     cout << "Number Guessing Game" << endl;
  17.     cout << "*****************" << endl;
  18.     cout << endl;
  19.     cout << "The random number been generated" << endl;
  20.     system("pause");
  21.    
  22.     while (g!=n)
  23.     {
  24.           system("cls");
  25.           cout << "Number Guessing Game" << endl;
  26.           cout << "********************" << endl;
  27.           cout << "Guess: ";
  28.           cin >> g; //Cin takes the input of user and stores it into the variable g
  29.           }
  30.          
  31.           system("cls");
  32.           cout << "You have found the number!" << endl;
  33.           cout << "The number was " << n << endl;
  34.           cout << "Press any key to play again" << endl;
  35.           system("pause");
  36.           goto play;
  37.      
  38.    return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement