Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Have no clue where to start

    Here is an assignment that I have been stuck on for about an hour. This is coding in C. Problem I'm having is reading an unknown number of values.
    ------------------------------
    Statisticians use many different algorithms in addition to the arithmetic average. Two other averages are
    the geometric and the harmonic mean.

    Write a program that reads a series of numbers and calculates the average, geometric mean, and harmonic
    mean. Do NOT use arrays for the series of numbers. Utilize functions for modularity.

    -----------------------------------
    I think I can totally manage this with using arrays, but without them I feel like I have no idea how to even start it. The functions and everything else will be easy to do, if I can find a way to read an unknown number of inputs. I couldn't think of any efficient ways to do so, maybe someone here could point me in the right direction. Thanks a lot!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,628
    Thanks
    0
    Thanked 648 Times in 638 Posts
    The arithmetic average is all the numbers added together and divided by how many numbers there were.

    To do that without an array you'd need two variables - both initially set to zero. Then as you read each number you add the number to the first variable and add 1 to the second variable. When you finish reading numbers the arithmetic average is the value in the first variable divided by the value in the second variable.


    For reading an unknown number of values you set up a loop that keeps reading until an end of file condition is obtained.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    javajerry (11-07-2013)

  • #3
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ah! Gotcha. I finally did it. Thank you very much!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •