1. Originally Posted by kbpsu
i know how to figure out the average and range if the numbers are known. but for this problem, i am not sure how many numbers the user is going to input, so i dont know what number to divide by. and for the range, i dont know how to get the program to recognize which number was the max/min.
yes, that's why i linked you the wiki page on how to calculate a moving average.

the key to your assignment is to just keep track of things as you go along.

2. so i dont know what number to divide by
Count the loop iterations?

3. The divide by will be different each iteration, which is why you need a simple counter which increases by one each time the user enters a number. The first number entered will just BE the average of course, but the second one will only get a 1/2 share. To add the fifth number into your ongoing average, you might use the following calculation:

mean=mean*(4/5) + number*(1/5)

If a sixth number is added, you'll need to update your average:

mean=mean*(5/6) + number*(1/6)

4. Originally Posted by rossipoo
The divide by will be different each iteration, which is why you need a simple counter which increases by one each time the user enters a number. The first number entered will just BE the average of course, but the second one will only get a 1/2 share. To add the fifth number into your ongoing average, you might use the following calculation:

mean=mean*(4/5) + number*(1/5)

If a sixth number is added, you'll need to update your average:

mean=mean*(5/6) + number*(1/6)
What you're saying is correct, but the exact implementation isn't -- (1/6) == 0. Since the counter is almost certainly an integer, you'll need a cast to double before doing the division.

But I wouldn't do it that way anyway -- I'd just count the iterations and divide once at the end. All those intermediate divisions and additions would make me nervous about floating point noise.

5. Oh yeah, duh, you can just divide the total at the end. You will need to go to a float though, unless the user happens to enter numbers that divide evenly, which isn't likely.