#include <iostream>usingnamespace std;
int main()
{
cout << "Give me secret number 1 to 100 "
<< "and I will guess it in 7 tries. Go!\n";
int y;
char ch;
cin >> y;
int tries = 1;
int x = 50;
int xl = 0;
int xh = 101;
cout << "How about " << x << "?\n";
if (x != y)
{
cout << "Was it too high a) or too low b)?\n";
cin >> ch;
if (ch == 'a')
{
xh = x;
x = 25;
}
elseif (ch == 'b')
{
xl = x;
x = 75;
}
cout << "How about now? " << x << endl;
tries++;
}
while (x != y)
{
cout << "Was it too high a) or too low b)?\n";
cin >> ch;
if (ch == 'a')
{
xh = x;
x -= (xh - (xl - 1)) / 2;
}
elseif (ch == 'b')
{
xl = x;
x += ((1 + xh) - xl) / 2;
}
cout << "How about now? " << x << endl;
tries++;
}
if (x == y)
{
cout << "Congratulations. It is " << x << endl
<< " after " << tries << ". try. \"Good job!\"";
}
return0;
}