So i'm doing some of the beginner exercises that was posted on this website
|
http://www.cplusplus.com/forum/articles/12974/
|
namely the "bracket search" i'm on the 4 star challenge and i'm having some problems :<
challenge:
|
Pick a number and have the program guess it. modify the program so that no matter what number the user thinks of (1-100) the computer can guess it in 7 or less guesses.
|
What i'm having problem with is getting rand() to do what i want. I want it to search in a specific range.
I understand it very basic like for example if i were to write
rand()% 100 + 1;
this would generate a number within the range 1-100 the problem occurs when i try to have ranges like from 40-50
i know the code for it would be
rand()% 10 + 40;
But i don't understand how i can get the program to update the specific range by itself.
so for example it would be like this
user has a number between 1-100 let's say he picks 19
the program generates the number 29
this number is higher than the what the user inputed
so the program should now search 1-29
the program generates 15
this number is lower than the one the user picked
so the program now searches 15-29
and so on til the program finds the correct number. but i have no idea how to do this, could anyone help? :>
i've done most of the code as i said it's the rand() part giving me trouble