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 as 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?

high and low - you want to reseed with the guess and one of the seeds. But wouldn't you want to reseed with guess+1 or guess-1 depending on whether it was to high or to low? And then when the upper and lower values become the same, well that's the number

guessnum(low,n-1) should be one of them. But to determine whether or not the computer is right, just compare high and low, if they are the same, then the computer knows the answer.