a function that performs 3 task

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chevon1920
    New Member
    • Feb 2008
    • 12

    a function that performs 3 task

    I need assistance writing a function that will perform three tasks. The first thing it must do is find the average of a set of data. Then it needs to use a pointer to increment the number above the average. Thanks all fine, but the last thing it has to do is print out the array of structures that have a value larger than average.

    How am I suppose to have a function return a double and print the array of structions at the same time?

    Anyone ever done this before?

    Thanks
  • questionit
    Contributor
    • Feb 2007
    • 553

    #2
    Originally posted by chevon1920
    I need assistance writing a function that will perform three tasks. The first thing it must do is find the average of a set of data. Then it needs to use a pointer to increment the number above the average. Thanks all fine, but the last thing it has to do is print out the array of structures that have a value larger than average.

    How am I suppose to have a function return a double and print the array of structions at the same time?

    Anyone ever done this before?

    Thanks
    Hi

    To return a double , you just have to have a function with return type 'double'
    The receiver (a variable) of of the returned value must of 'double' type.

    To print an array of structure (assume it contains data). You need a loop over each structure and display contents of each structure by referring to structure members.

    Hope it helps
    Regards
    Qi

    Comment

    • chevon1920
      New Member
      • Feb 2008
      • 12

      #3
      Originally posted by questionit
      Hi

      To return a double , you just have to have a function with return type 'double'
      The receiver (a variable) of of the returned value must of 'double' type.

      To print an array of structure (assume it contains data). You need a loop over each structure and display contents of each structure by referring to structure members.

      Hope it helps
      Regards
      Qi
      Hi, thanks for your reply. I understand how to do that, the problem I'm having is normally when you have a function print something it returns nothing. How can i write a function that returns a double and it prints in the main when its called, at the same time? Is that even possible? I would assume that when I call the function it will just print the double instead of printing out what I needed it to.
      Thanks for any help!

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by chevon1920
        Hi, thanks for your reply. I understand how to do that, the problem I'm having is normally when you have a function print something it returns nothing. How can i write a function that returns a double and it prints in the main when its called, at the same time? Is that even possible? I would assume that when I call the function it will just print the double instead of printing out what I needed it to.
        Thanks for any help!
        You can print inside your function and have it return a value.
        When the output is displayed, nobody can tell whether the output was done from your function or from the main function.

        Comment

        Working...