The major issue I'm currently having is that it's not changing the variable guess to the estimate, keep thinking that it's still 100+1/2 so constantly outputs 50. I'm sure I'm missing a way to change the constant within the switch or I'm missing a loop but I don't see it right now :[
Any help/advice would be greatly appreciated!
The code is as follows
#include <iostream>
using namespace std;
int main()
{
int low = 1, high = 100;
bool correct = false;
int guess = (high + low) / 2;
int response;
int counter=1;
cout << "Think of a number between 1 and 100\n";
cout << "tell me if I'm too high(1), too low(2), or if I'm correct(3)\n";
do
{
cout << "My guess is " << guess << " ,is it..\n";
cout << "1 - High?\n";
cout << "2 - Low?\n";
cout << "3 - Correct?\n";
cin >> response;
for(counter = 1; counter >=100; counter++);
switch(response)
{
case 1:
high = guess - 1;
break;
case 2:
low = guess + 1;
break;
case 3:
correct = true;
break;
default:
cout << "Invalid response\n";
continue;
}
}
while(!correct);
cout << "Your number is " << guess << "this was achieved in " << counter << "tries.\n";
return 0;
}