#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {
    constexpr char yes = 'y';
    constexpr char no = 'n';

    int left = 1;
    int right = 100;

    cout << "Guess the number from " << left << " to " << right << "." << endl;
    cout << "Further enter \"" << yes << "\" if the answer is yes, or \"" << no << "\" if the answer is no." << endl;

    while (right - left > 1) {
        int approximation = (left + right) / 2;
        cout << "Is your number less than " << approximation << "?" << endl;

        char answer = ' ';
        while (true) {
            cout << ">>> ";
            cin >> answer;
            if (answer == yes || answer == no) {
                break;
            } else {
                cout << "I do not get it. Please, follow the above rule entering the answer." << endl;
            }
        }

        switch (answer)	{
        case yes:
            right = approximation;
            break;
        case no:
            left = approximation;
            break;
        default:
            break;
        }
    }

    cout << "Your number is " << left << "." << endl;
}
