Velocity Reviews > function problem

# function problem

Learning Learner
Guest
Posts: n/a

 06-18-2010
I know this must have some simple answer but I'm having trouble with
this function I wrote.

stdio.h
math.h

double relstr (double x,double y)
{double n;
n=x/y;
printf("%f",(return n);}

I dunno.

Ian Collins
Guest
Posts: n/a

 06-18-2010
On 06/18/10 04:30 PM, Learning Learner wrote:
> I know this must have some simple answer but I'm having trouble with
> this function I wrote.
>
> stdio.h
> math.h
>
> double relstr (double x,double y)
> {double n;
> n=x/y;
> printf("%f",(return n);}
>
> I dunno.

So I see. What on earth is that supposed to do?

--
Ian Collins

Peter Nilsson
Guest
Posts: n/a

 06-18-2010
Learning Learner <(E-Mail Removed)> wrote:
> I know this must have some simple answer but I'm having
> trouble with this function I wrote.
>
> stdio.h
> math.h

Is that what's in your source, or are you using a bad
editor to post to usenet?

> double relstr (double x,double y)
> * * * * * * {double n;
> * * * * * * * n=x/y;
> * * * * * * * printf("%f",(return n);}

The return keyword marks a statement, not an expression.

You can't use a statement as a form of expression in standard C.
Are you learning from a reference book or tutorial? It seems
you're trying to learn C by guesswork. My advice is... DON'T!
It's the worst language for that!

--
Peter

Mark Bluemel
Guest
Posts: n/a

 06-18-2010
On 18 June, 05:45, Peter Nilsson <(E-Mail Removed)> wrote:
> ... It seems
> you're trying to learn C by guesswork. My advice is... DON'T!
> It's the worst language for that!

You've never encountered Intercal then?

Oliver
Guest
Posts: n/a

 06-18-2010
On Jun 18, 12:30*pm, Learning Learner
<(E-Mail Removed)> wrote:
> I know this must have some simple answer but I'm having trouble with
> this function I wrote.
>
> stdio.h
> math.h
>
> double relstr (double x,double y)
> * * * * * * {double n;
> * * * * * * * n=x/y;
> * * * * * * * printf("%f",(return n);}
>
> I dunno.

I also dunno.

printf("%f", (return n);

"return n;" will always run earlier than printf(), so?

double relstr(double x, double y)
{
double n;

n = x/y;
printf("%f", n);
return n;
}

is above you want?

Keith Thompson
Guest
Posts: n/a

 06-18-2010
Oliver <(E-Mail Removed)> writes:
> On Jun 18, 12:30Â*pm, Learning Learner
> <(E-Mail Removed)> wrote:
>> I know this must have some simple answer but I'm having trouble with
>> this function I wrote.
>>
>> stdio.h
>> math.h
>>
>> double relstr (double x,double y)
>> Â* Â* Â* Â* Â* Â* {double n;
>> Â* Â* Â* Â* Â* Â* Â* n=x/y;
>> Â* Â* Â* Â* Â* Â* Â* printf("%f",(return n);}
>>
>> I dunno.

>
> I also dunno.
>
> printf("%f", (return n);
>
> "return n;" will always run earlier than printf(), so?

No, "return n;" will not run at all, because it's a syntax error.
"return n;" is a statement, and statements cannot appear within
expressions.

[...]

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Richard Bos
Guest
Posts: n/a

 06-19-2010
Kenneth Brody <(E-Mail Removed)> wrote:

> On 6/18/2010 3:53 AM, Mark Bluemel wrote:
> > On 18 June, 05:45, Peter Nilsson<(E-Mail Removed)> wrote:

> >> you're trying to learn C by guesswork. My advice is... DON'T!
> >> It's the worst language for that!

> >
> > You've never encountered Intercal then?

>
> ITYM "INTERCAL". It's an acronym meaning "Compiler Language With No
> Pronounceable Acronym", not a proper noun.

I've never understood what's supposed to be so unpronouncable about
Clwnpa. Any Welshman could tell you exactly how that is pronounced.

Richard

Joachim Schmitz
Guest
Posts: n/a

 06-20-2010
Richard Bos wrote:
> Kenneth Brody <(E-Mail Removed)> wrote:
>
>> On 6/18/2010 3:53 AM, Mark Bluemel wrote:
>>> On 18 June, 05:45, Peter Nilsson<(E-Mail Removed)> wrote:

>
>>>> you're trying to learn C by guesswork. My advice is... DON'T!
>>>> It's the worst language for that!
>>>
>>> You've never encountered Intercal then?

>>
>> ITYM "INTERCAL". It's an acronym meaning "Compiler Language With No
>> Pronounceable Acronym", not a proper noun.

>
> I've never understood what's supposed to be so unpronouncable about
> Clwnpa. Any Welshman could tell you exactly how that is pronounced.

Looks like a common welsh first name

Bye, Jojo