So started learning C++ almost a week ago and now I am studying from a new text book I just got Beginning c++ through game programming, Third Edition. Earlier in the chapter there is an example code that creates a "Guess my number" program where the user enters a value and the computer tells you if you need to guess higher or lower...and eventually when you guess the right value it tells you Congrats and how many tries it took you to guess.
Now the objective of the Exercise at the end of the chapter, is to switch this program around and have the user enter a secret number then, have the computer guess what number the user entered.
Problem:
The program runs and loops correctly. (I think) The random numbers generate but I'm unsure of how to make the computer "smarter" I guess and to help it get to the ultimate objective of having it eventually guess my number.
Please Help!
Thank you very much in advance!
-Jeff
On the first guess, the number must be somewhere in the range 1 to 100.
After the user indicates either higher or lower, you can narrow the range, as either the upper limit can be set to one less than the previous guess, or the lower limit can be set to one more than the previous guess. Thus the next guess is made within that narrower range.
You can continue to make a random guess within those new limits, or more boringly but more efficiently, pick the number in the middle.
Repeat until the guess is correct, or the upper and lower limits meet.