# Have no clue where to start

• 11-01-2013, 10:34 PM
javajerry
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!
• 11-02-2013, 12:09 AM
felgall
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.
• 11-02-2013, 05:19 AM
javajerry
Ah! Gotcha. I finally did it. Thank you very much!