Advertisement
Luxeon94

(EXP) Random number guesser

Dec 16th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. void find(int r, bool easier){
  6.     bool found = false;
  7.         int n;
  8.         int count = 0;
  9.         bool cheat=false;
  10.         while(not found and cin >> n){
  11.             if(n == 10000){
  12.                 cout << "You cheater huh?" << endl;
  13.                 cout << "Okay then... Answer is " << r << endl;
  14.                 cheat=true;
  15.             }
  16.             ++count;
  17.             if(n == r) found=true;
  18.             else if(easier){
  19.                 if(n<r) cout << "The answer is higher than that!" << endl;
  20.                 else cout << "The answer is lower than that!" << endl;
  21.             }
  22.         }
  23.         if(found){
  24.             cout << endl << "The number was " << r << "!" << endl;
  25.             cout << "Total attempts: " << count << endl << endl;
  26.             cout << "Continue?" << endl;
  27.             if(cheat) cout << "You're a cheater anyway..." << endl;
  28.         }
  29. }
  30.  
  31. int main(){
  32.     int r;
  33.     int dif;
  34.     string y;
  35.     do{
  36.         cout << "Choose your difficulty!" << endl;
  37.         cout << "1: coinflip; 2: easy; 3: hard; 4: SHINY" << endl;
  38.         cin >> dif;
  39.         dif-=1;
  40.         dif%=4;
  41.         if(dif==0) r = rand() % 2;
  42.         else if(dif==1) r = rand() % 10;
  43.         else if(dif==2) r = rand() % 100;
  44.         else r = rand() % 4096;
  45.         bool easier;
  46.         cout << "Easier mode? 1: yes; 0: no" << endl;
  47.         int em;
  48.         cin >> em;
  49.         em%=2;
  50.         if(em==1) easier=true;
  51.         else easier=false;
  52.         find(r, easier);
  53.     } while(cin >> y and y!="no");
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement