Advertisement
JustACodingStudent

Guessing Game

Mar 28th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int num, tries, guess;
  9.     //Randomizer
  10.     srand(time(0));
  11.     num = 1 + rand()%10;
  12.     //Creates the random number.
  13.     //Sets the tries at 3.
  14.     tries = 3;
  15.     //Loops the program while the user's guess isn't the number.
  16.     do{
  17.         //Allows user to input guess.
  18.         cout << "Tom is Gay): ";
  19.         cin >> guess;
  20.         //Subtracts tries.
  21.         if(guess == num - 3 || guess == num + 3){
  22.             //If off by 3, displays "cold."
  23.             cout << "You're cold! Try again.\n" << endl;
  24.             tries = tries - 1;
  25.         }
  26.         else if(guess == num - 2 || guess == num + 2){
  27.             //If off by 2, displays "warm."
  28.             cout << "Warmer! Try again.\n" << endl;
  29.             tries = tries - 1;
  30.         }
  31.         else if(guess == num - 1 || guess == num + 1){
  32.             //Iff off by 1, displays "hot."
  33.             cout << "Red hot! Try again.\n" << endl;
  34.             tries = tries - 1;
  35.         }
  36.         else if(guess != num){
  37.             //If off by 4 or more, displays "way off."
  38.             cout << "You're WAY off. Try again.\n" << endl;
  39.             tries = tries - 1;
  40.         }
  41.         else{
  42.             //If you get it, you win!
  43.             cout << "Eureka! You got it! Good job." << endl;
  44.             system("pause");
  45.         }
  46.         if(tries == 0){
  47.             //Closes program once the user runs out of tries.
  48.             cout << "You've run out of tries. Tough luck scrub." << endl;
  49.             system("pause");
  50.         }
  51.     }while(guess != num);
  52.     int x;
  53.     cin>>x;
  54.     return(0);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement