|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (9 bit)
Join Date: Jun 2003
Posts: 290
|
programming help needed !!!
I am supposed to make a program where the user selects a number between 1 and 100 and then the computer will attempt to guess that number. After each guess, the use will enter whether the number was too high or too low. So far i have this,
function guessnum(low,high) n=floor((high-low)/2); disp(sprintf('%d',n)); ans = input('High or Low? ','s') if strcmp(ans,'correct') disp(sprintf('Computer wins')); elseif strcmp(ans,'high') guessnum( ,n); elseif strcmp(ans,'low') guessnum(n, ); end the thing i am having trouble with is what to put with each recursive function call. I know that if the number is too high, return that guess has the upper bound and vice versa with the lower bound. I just don't know how to calculate the lower bound if the guess is too high or the higher bound if the guess is too low. can OT help me out? |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|