Advertisement
Guest User

Guessing game

a guest
Mar 9th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <time.h>
  4. #include <conio.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main(){
  10.  
  11.     int z;
  12.     int x;
  13.  
  14.     char option;
  15.     char rematch;
  16.     /*char letters[29] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'z', 'æ', 'ø', 'å', 'y', 'w' };*/
  17.  
  18.     bool replay;
  19.  
  20.     do{
  21.  
  22.  
  23.         srand(time(NULL));
  24.         z = (rand() % 365241 ^ 215);
  25.  
  26.         system("cls");
  27.  
  28.     cout << "Choose difficulity" << endl;
  29.     cout << "(H) Hard 1-5000" << endl;
  30.     cout << "(M) Medium 1-500" << endl;
  31.     cout << "(E) Easy 1-50" << endl;
  32.  
  33.     cin >> option;
  34.  
  35.         /*for (int i = 1; i < 29; i++){
  36.             if (letters[i] == x){
  37.                 cout << "You dumb trash-tier shitnigger, this was intended for fucking integers" << endl;*/
  38.             /*}*/
  39.        
  40.  
  41.     if ((option == 'H') || (option == 'h'))  {
  42.  
  43.             srand(z);
  44.             x = 1 + (rand() % 5000);
  45.  
  46.     }
  47.  
  48.     else if ((option == 'M') || (option == 'm')) {
  49.  
  50.         srand(z);
  51.         x = 1 + (rand() % 500);
  52.    
  53.     }
  54.  
  55.     else if ((option == 'E') || (option == 'e')) {
  56.  
  57.         srand(z);
  58.         x = 1 + (rand() % 50);
  59.  
  60.     }
  61.    
  62.  
  63.     cout << x << endl;
  64.  
  65.     int number;
  66.     cout << "Type in you number: ";
  67.     cin >> number;
  68.  
  69.     // loop
  70.  
  71.     bool done = false;
  72.    
  73.     do
  74.  
  75.     {
  76.  
  77.         // Comparison operators: == != > < >= <=
  78.  
  79.         if (!(cin >> x))
  80.         {
  81.             cin.clear();
  82.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  83.             cout << endl << "Input must be an integer" << endl << endl;
  84.             cout << "Type in you number: ";
  85.         }  
  86.  
  87.         else if (number <= x) {
  88.             cout << "\nThat number is too low, try again" << endl;
  89.             cout << "Type in your next guess: ";
  90.             cin >> number;
  91.         }
  92.  
  93.         else if (number >= x) {
  94.             cout << "\nThat number is too high, try again" << endl;
  95.             cout << "Type in your next guess: ";
  96.             cin >> number;
  97.         }
  98.  
  99.         if (number == x) {
  100.             cout << "\nYou're right" << endl;
  101.             cout << "Do you want to play again?" << endl;
  102.             cout << " Press Y for yes or N for no" << endl;
  103.  
  104.             cin >> rematch;
  105.  
  106.             if ((rematch == 'Y') || (rematch == 'y')) {
  107.  
  108.                 replay = true;
  109.                 done = false;
  110.                 break;
  111.  
  112.             }
  113.  
  114.             else if ((rematch == 'N') || (rematch == 'n')){
  115.  
  116.  
  117.                 exit(0);
  118.             }
  119.  
  120.         }
  121.  
  122.         /*if (done == true) {
  123.            
  124.         }*/
  125.  
  126.     } while (done == false);
  127.     } while ((rematch == 'Y') || (rematch == 'y')); {
  128.         return 0;
  129.     }
  130.    
  131.  
  132.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement