# function problem

Discussion in 'C Programming' started by Learning Learner, Jun 18, 2010.

1. ### Learning LearnerGuest

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.

Learning Learner, Jun 18, 2010

2. ### Ian CollinsGuest

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

Ian Collins, Jun 18, 2010

3. ### Peter NilssonGuest

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

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

Peter Nilsson, Jun 18, 2010
4. ### Mark BluemelGuest

On 18 June, 05:45, Peter Nilsson <> 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?

Mark Bluemel, Jun 18, 2010
5. ### OliverGuest

On Jun 18, 12: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.

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?

Oliver, Jun 18, 2010
6. ### Keith ThompsonGuest

Oliver <> writes:
> On Jun 18, 12: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.

>
> 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.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson, Jun 18, 2010
7. ### Richard BosGuest

Kenneth Brody <> wrote:

> On 6/18/2010 3:53 AM, Mark Bluemel wrote:
> > On 18 June, 05:45, Peter Nilsson<> 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

Richard Bos, Jun 19, 2010
8. ### Joachim SchmitzGuest

Richard Bos wrote:
> Kenneth Brody <> wrote:
>
>> On 6/18/2010 3:53 AM, Mark Bluemel wrote:
>>> On 18 June, 05:45, Peter Nilsson<> 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

Joachim Schmitz, Jun 20, 2010