Advertisement
GunnerJnr

Guess The Number

Jul 13th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. // Guess The Number V1.0 - A simple number guessing game,
  2. // produces a random number then prompts the user to enter their guess
  3.  
  4. // Include the header files required
  5. #include <ctime>
  6. #include <cstdlib>
  7. #include <iostream>
  8. #include <string>
  9.  
  10. // using namespace declaration
  11. using namespace std;
  12.  
  13. // Main Program entry Point
  14. int main()
  15. {
  16.     // Here we generate random numbers using the current time
  17.     srand((unsigned int)time(NULL));
  18.  
  19.     // Next we get a random number between 0 and 200
  20.     unsigned int numberToGuess = rand() % 201;
  21.  
  22.     // output a message to the user
  23.     cout << "Choose a number between 0 & 200 : " << endl;
  24.  
  25.     // variable to hold the user's value
  26.     unsigned int userNumber;
  27.  
  28.     // output message to user
  29.     cout << "You're Guess? : ";
  30.  
  31.     // this will store the users number
  32.     cin >> userNumber;
  33.  
  34.     // output the results to the console
  35.     cout << "You guessed : "
  36.          << userNumber
  37.          << endl
  38.          << "The actual number was : "
  39.          << numberToGuess
  40.          << endl << endl;
  41.  
  42.     // get input from user before closing the window
  43.     system("pause");
  44.     // let the program know we have finished without error and exit
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement