# i need some programming h elp

Discussion in 'OT Technology' started by notwist, Feb 27, 2005.

1. ### notwistActive Member

Joined:
Nov 8, 2004
Messages:
5,737
0
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?

2. ### 5Gen_PreludeThere might not be an "I" in the word "Team", but

Joined:
Mar 14, 2000
Messages:
14,523
9
Location:
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

Joined:
Nov 8, 2004
Messages:
5,737
0
huh?

Joined:
Mar 14, 2000
Messages:
14,523