Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: function- help needed!
Date: Mon, 17 Aug 2009 09:21:40 -0400
Organization: The MathWorks, Inc.
Lines: 50
Message-ID: <h6blgv$m6t$1@fred.mathworks.com>
References: <h6beq6$1e1$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1250515295 22749 172.31.44.65 (17 Aug 2009 13:21:35 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 Aug 2009 13:21:35 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-RFC2646: Format=Flowed; Original
Xref: news.mathworks.com comp.soft-sys.matlab:563950


"lou lou Pengant" <bad22@bad.com> wrote in message 
news:h6beq6$1e1$1@fred.mathworks.com...
> Create a matlab function called birthday. The argument of the function is 
> a , where a is a persons age.
>
> if a is less than 21 then the function must output a text string of the 
> following form:
> eg, if a=7, the text string should be 'I am 7 years old'
>     if a=10, the text string should be 'I am 10 years old'
>
> However, if a is 21 or over, the output text string should be 'I have 
> passed my 21st birthday'
>
>
> I am having difficulty with creating the first part of the question, when 
> ages are less than 21- I dont know how to make the age in the text string 
> a variable.
>
> function [display]=birthday(a)
> a=input('How old are you?');
> if a>=21;
>    disp('I have passed my 21st birthday')
> elseif a<21
> THIS IS THE LINE THAT I NEED HELP ON!!
> end
> end

Note that your code receives an input argument, a, when you call it ... but 
then you overwrite that input argument with the output argument from your 
INPUT call.  I'm guessing this is a homework assignment (and the rest of 
this post will follow that assumption) and I'm also guessing that your 
professor will call that behavior out when he or she grades it.  I would 
remove that INPUT statement entirely.

Also, you specify in the function declaration line that this function will 
return one output argument, the variable inside birthday that's called 
display.  However, you never create a variable named display inside 
birthday, so you will probably receive an error when you call this function 
with an output argument.  Because of that and the wording of the problem 
statement you posted above, this program does not satisfy that problem 
statement, and your professor will likely call that out too during grading. 
Rather than displaying the string inside birthday, return it as an output 
argument.

-- 
Steve Lord
slord@mathworks.com