Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h"
- using namespace std;
- int main()
- {
- int numb;
- cout<<"Enter a number between 1 and 100";
- cin>>numb;
- bool guessed=false;
- int min=0;
- int max=100;
- int balance=0;
- int guess_int;
- while(!guessed)
- {
- balance=(int)(max+min)/2;
- cout<<"Is your number less than "<<balance<<" type 1 for yes, and 2 for no.";
- cin>>guess_int;
- if(guess_int==1)
- max=balance-1;
- else
- min=balance;
- if(balance==numb){
- cout<<"Your number is: "<<balance<<".";
- guessed=true;}
- }
- cout<<"Got it!";
- }
Add Comment
Please, Sign In to add comment