Functions

This is a discussion on Functions within the C++ Programming forums, part of the General Programming Boards category; Thank you...

  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 05:02 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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,892
    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 05:02 PM.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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 05:03 PM.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21