OK so I'm stuck on another problem.
I'm trying to write a program that you guess a number in your head 1-100 and then the computer asks you if its lower than 50 to start the process of elimination... I tired of and tried and failed at it - maybe someone here can help me :)
It should also not take more than 7 guess for the computer to figure out the problem either. I'm trying to make the formula so when the two numbers ( highernum and lowernum) match up it will automatically spit out the number you guess but I'm trying to figure out the formula with no avail.... any ways here my code - it also asks me in the beginning the same question twice which I want to get fixed also:
#include <iostream>
usingnamespace std;
int main()
{
int input;
int highernum = 100;
int lowernum = 1;
cout << "Guess a number between 1 and 100\n"
<< "When your ready to begin press enter.";
cin.get();
cout << "Is the number you are thinking of lower than " << highernum / 2 << "?\n- 1 for yes - 2 for no - 3 to quit -\nEnter number: ";
while (cin >> input)
if (input == 1)
{
lowernum += 0;
highernum = (lowernum + highernum) / 2;
cout << "\nIs the number you are thinking of lower than " << highernum << "?\n- 1 for yes - 2 for no - 3 to quit -\nEnter number: ";
}
elseif(input == 2)
{
lowernum = highernum + 1;
highernum = (highernum + lowernum) -2;
cout << "Is the number you are thinking of lower than " << highernum << "?\n- 1 for yes - 2 for no - 3 to quit -\nEnter number: ";
}
elseif(input == 3)
{
cout << "The program will now terminate...\n";
cin.get();
return 1;
}
elseif(lowernum = highernum )
{
cout << "I guess that your number is " << highernum << "!\n";
break;
}
return 0;
}
#include <iostream>
usingnamespace std;
int main() {
int input = 0;
int highernum = 100;
int lowernum = 1;
cout << "Guess a number between 1 and 100\nWhen your ready to begin press enter.";
cin.get();
cout << "Is the number you are thinking of lower 50\n'y' or 'n'\n";
while (cin >> input)
if (input == 'y')
{
lowernum += 0;
highernum = (lowernum + highernum) / 2;
cout << "Is the number you are thinking of lower than " << highernum << "?\n";
}
elseif(input == 'n') {
lowernum = highernum + 1;
highernum = (highernum + lowernum) / 2;
cout << "Is the number you are thinking of lower than " << highernum << "?\n";
}
elseif(lowernum = highernum ) {
cout << "I guess that your number is " << highernum << "!\n";
break;
}
return 0;
}