///Geoff Hagopian doing exercise 4.4 of PPP

/*************
4. Write a program to play a numbers guessing game. The user thinks
of a number between 1 and 100 and your program asks questions to figure
out what the number is (e.g., “Is the number you are thinking of less than 50?”).
Your program should be able to identify the number after asking
no more than seven questions. Hint: Use the < and <= operators and
the if-else construct.
******/

#include "..\std_lib_facilities.h"

int main() {
    cout << "\nThink of a number between 1 and 100";
    int left = 1, right = 100;
    bool found=0, yes=0;
    while(!found) {
        cout << "\nIs your number " << (left+right)/2 << "? ";
        cin >> yes;
        if(yes) {
            found = 1;
            break;
        }
        cout << "\nIs your number greater than " << (left+right)/2 << "? ";
        cin >> yes;
        if(yes) left = (left+right)/2;
        else right = (left+right)/2;
    }
    if(found) cout << "\nHooray, you found the number is " << (left+right)/2;
    else cout <<"\nFailure!";
}
