Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 02-27-2005, 04:13 PM   #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?
ACLerok is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:18 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2