function problem

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

  1. 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
    #1
    1. Advertising

  2. Learning Learner

    Ian Collins Guest

    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
    #2
    1. Advertising

  3. 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
    #3
  4. Learning Learner

    Mark Bluemel Guest

    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
    #4
  5. Learning Learner

    Oliver Guest

    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
    #5
  6. 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
    #6
  7. Learning Learner

    Richard Bos Guest

    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
    #7
  8. 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 :cool:

    Bye, Jojo
    Joachim Schmitz, Jun 20, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Vanns
    Replies:
    7
    Views:
    7,014
    Evan Carew
    Jan 21, 2004
  2. komal
    Replies:
    6
    Views:
    1,409
    msalters
    Jan 25, 2005
  3. Replies:
    2
    Views:
    896
    Bengt Richter
    Aug 1, 2005
  4. Giannis Papadopoulos

    Function pointer to void function and int function

    Giannis Papadopoulos, Sep 5, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,218
    Barry Schwarz
    Sep 5, 2005
  5. weafon
    Replies:
    1
    Views:
    290
    Diez B. Roggisch
    Jul 14, 2009
Loading...

Share This Page