Write a program that asks the user to think of a number between 1 and 100, then
ID: 3622996 • Letter: W
Question
Write a program that asks the user to think of a number between 1 and 100, then attempts to guess teh number. The program should make an initial guess of 50. The program should then ak the user if 50 is the number the user has in mind, or if 50 is too high or too low. Based on the response given by the user, the program should make another guess. Your program must continue to guess until the correct number is reached. Save the sorce file as HI-LO.cppI really need help with this one! This is not for HW points, but my teacher said if I don't get this then I wont understand the whole chapter. If anyone can get me started that would be great. The complete code is NOT required, but would be helpful :)
Explanation / Answer
please rate - thanks
#include <iostream>
#include<ctime>
using namespace std;
int main()
{int number,hi=100,lo=1;
char hilo='k';
cout<<"Think of a number between 1 and 100 ";
while(hilo != 'c')
{number=(hi+lo)/2;
cout<<"Is it a "<<number<<"?(enter h for too high, l for too low, c for correct): ";
cin>>hilo;
if(hilo=='h')
hi=number;
else if(hilo=='l')
lo=number;
}
system("pause");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.