guessing game

hi!
We have a project about guessing game..
The requirement goes like this.
The user will hide a number from 0-99 then,the computer will be the one to guess it. When the computer have already showed its guess, the user will tell if it is higher or lower compared to the hidden number.
Can you give us an idea on how to do this?Thank you.
Hello.

You can try this way which resembles binary searching.
First, you initialize two variables, low and hi, to the lowest and the highest values of the range (0 and 99 in your example); then, you generate your first guess as "guess = (low + hi)/2".
Then you show it to the user. If the user replies that your guess is smaller, you update low as guess+1; if it's bigger, you update hi as guess -1.
Eventually the PC will guess it right in no more that ceil(log2(hi - low + 1)) + 1 tries.

Good luck!
actually.. it's the other way around..

If the user says smaller, update high as guess-1, and if they say larger, update low as guess+1

you could always devide between the two, but I think i'd rather do it similar to a human would do it.. (a smart human) and round to the nearest 10, untill you get within 10 from the guess, then split the difference to 5, then go through each digit in turn for those 5 till correct.

It sort of adds a bit of humanality to it, and would similate the way a smart human would do it.

As for a not-so-smart human, still use the low and high variables and just take random guesses while updating the low and high
hi,.

i am having one more thought.
suppose user is going to guess a no with in 99 no's. after some caliculation v can give his guess no. like......
if user took 34 as his no. after that ha has to do individual number additions
i.e, 3+4=7, this 7 is going to decrease the main value.
i.e, 34-7=27, now he is remembering 27 . we r going to display a symbol that symbol points to 27.

for pointing symbol....
we r going to display 99 different symbols. we r going to place the same symbol at 9 mutiples, like 0,9,18,27, .... till 99 then any how this operation gives 9 multiple only.
Hi everyone am Having a Problem with my c++ compiler whenever i run a simple program, it will just run and disappear without staying on my screen.
the compiler am using is the Dev 5 beta version.
where can i download a compiler that can work well.

PS
Smokie
Topic archived. No new replies allowed.