Thread: Functions

  1. #1
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76

    Smile Functions

    Thank you
    Last edited by lifeis2evil; 11-13-2007 at 06:02 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The names of the functions should give you hints. The display function is only there to display the values. It's getAndCalcAverages's job to calculate the average. Note that you got the return type wrong. It's supposed to be float - it's supposed to be the average.

    That's why display has four parameters: the three numbers plus the average.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well given the prototype, maybe you're supposed to pay attention to the return result,

    avg = getAndcalcAverages(firstNumber,secondNumber,thirdN umber);

    And perhaps avg is the 4th float passed to display()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    Thank you
    Last edited by lifeis2evil; 11-13-2007 at 06:02 PM.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    No. Did you even change anything?

    You have to calc the averages in the function that has "calcAverages" in its name.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And you have to return it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    Thank you
    Last edited by lifeis2evil; 11-13-2007 at 06:02 PM.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You have to do more work. You have to change the return type of the function. You also have to use the returned value.

    Do you remember how to use functions that return values? Go back to your book/notes/reference and brush up on the details.

  9. #9
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    Thank you
    Last edited by lifeis2evil; 11-13-2007 at 06:03 PM.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Looks better.
    Now to remove that conio dependency, and you're all good to go.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM