C++ help!

a1sporty15

In Runtime
Messages
102
I have to write a program that makes the computer guess your number. Ok first you input your number then the computer guesses it such as "is your number greater than 25 then less than 37 until it reachers your number. I have this all done but it does not seem to work.. It compiles normally and everything but the out put does not work....

http://www.copypastecode.com/codes/view/1327

Also there has to be an easier way to write this program...
 
There definitely is an easier way to write this. I wrote a similar program fro a number guessing game where the computer would tell you how far off you were. What you have to do is make the computer ask (assuming input is from 0-100) if your number is greater or lower than the midpoint of the range:

"Is your number greater than or less than 50?"

Then whatever answer you get you divide the new range again. So if the user answers "lower" the computer will ask:

"Is your number greater than or less than 25?"

You keep this going until the range is 1. To do this you can create a while-loop that will test while some Boolean variable is false. Definite it correct, or guess, or something. When the person guesses it correctly, you change it to true and snap out of the loop. You can then create variables for the upper, lower, and midpoint of the range. Depending on the user's answer you change an old upper or lower to the old midpoint. Then to find the new midpoint you find the difference in the range, divide it by two, and add/subtract from the lower/upper (doesn't matter which you do so long add to the lower or subtract from the upper).

If you don't know loops look for a quick tutorial on google, or if you want I'll teach it real quick.
 
Back
Top Bottom