Guest User

Untitled

a guest
Nov 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include "std_lib_facilities.h"
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int numb;
  7.     cout<<"Enter a number between 1 and 100";
  8.     cin>>numb;
  9.     bool guessed=false;
  10.     int min=0;
  11.     int max=100;
  12.     int balance=0;
  13.     int guess_int;
  14.     while(!guessed)
  15.     {
  16.         balance=(int)(max+min)/2;
  17.         cout<<"Is your number less than "<<balance<<" type 1 for yes, and 2 for no.";
  18.         cin>>guess_int;
  19.         if(guess_int==1)
  20.             max=balance-1;
  21.         else
  22.             min=balance;
  23.         if(balance==numb){
  24.             cout<<"Your number is: "<<balance<<".";
  25.             guessed=true;}
  26.     }
  27.     cout<<"Got it!";
  28. }
Add Comment
Please, Sign In to add comment