Hi , i'm trying to do an exercise where the computer has to guess the random number from the range of 1-1000. Currently this is the way i have it set up as. I divide that range in half and store it in guess and then check it against the random number. I'll continue to mod by 2 and compare it against random until i have a match. I dont know if this is the better way to go, any suggestions ? Thanks.
Crutoy
0
Junior Poster in Training
Recommended Answers
Jump to PostYou might also want to do something if the guess is too high, too low or correct.
example:
you enter a random number say => 765
The computer guesses 500 which is too low so the next number is one half of the high range => 750...and …
Jump to Post>> mod by 2
What's this mean? Be precise. I assume you mean you split the possible range in half, pick one side, then guess the midpoint of that side, then do it again and again till you find it. That's a binary search. That's fine, but you left …
Jump to PostYou seem to think that intermediates are attempts that is not the case,
I don't understand how you can skip that test of 875, it is a guess, and too high a guess.e.g.
computer value: 789 minValue=1; maxValue=1000; for(int i=0;i<10;i++) { guess=(maxValue+minValue)/2; // set maxValue …
All 10 Replies
gerard4143
371
Nearly a Posting Maven
VernonDozier
2,218
Posting Expert
Featured Poster
spoonlicker
-20
Junior Poster
Crutoy
0
Junior Poster in Training
spoonlicker
-20
Junior Poster
Crutoy
0
Junior Poster in Training
StuXYZ
731
Practically a Master Poster
Crutoy
0
Junior Poster in Training
Crutoy
0
Junior Poster in Training
Crutoy
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.