# Thread: loops and I/O file.

1. ## loops and I/O file.

I am stuck trying to write a program.
The program is supposed to do the following things:
1. accept 10 floating point numbers from a user,add all and divide by ten to get the average.
2. use two formulas to calculate a standard deviation.
3. display the results and any numbers that were input which are not four standard deviations away from the average should be dropped and a new average and deviation calculated.

I know we are to use looping methods for the formula. I started with a loop to calculate the average. So I thought within that loop I would call a function to execute the deviation formula (number - average squared) but that wouldn't work because the average has not been calculted yet. My question is where can I store these numbers? Also, can I execute this formula wherever I store them?
One more thing, when writing number-average squared, is the syntax as follows:
pow((number-average),2)

2. you need to post some code and point out your problems then...

nobody here will do your homework for you....

show us some effort and you shall receive help...

3. ok i just need you to tell me how far ahead are you in your class, have you covered classes and pointers???... and it would really help if you post code that you were working on, so i could follow your idea and coding form...

Regards,
matheo917

4. declare array of 10 floats.
declare a float to act as a running total and initialize to zero.
declare a float to act as the standard deviation.
declare an int to act as the number of floats used to calculate the average and assign it the value of 10.
declare an array of ten floats to hold each deviation.
declare an char to act as a flag and assign it the value of F.

use a loop to get user input for ten floats assigning each one to a successive element of the array.

use a while loop to run all of the calculations. use the flag equal to F as the conditional

use a loop to add each element of the array to the running total.

divide the running total by number of floats used to calculate the average. Assign the value to average.

use a loop to calculate the deviation for each element of the original array.

reset the running total to zero.

use a loop to add each deviation to running total.

divide running total by the number of elements in the array to get the standard deviation.

set the flag to T.

use a loop to compare each deviation from the original standard deviation. If any of the original float inputs are greater four times the standard deviation remove them from the array by shifting all elements of the original input array to the left by one and decrease the int by one and change the flag to value F.

if the flag is F reset the running total to zero and recalculate a new standard deviation using the new input array, etc. Repeat the process until all values in the array are less than four standard deviations from the mean.

once the control loop stops running (because the flag remains T) display the average, standard deviation, and whatever other information you wish/need to display.

If you allow use of negative numbers then there are a few more twists to the plot but if you know how to do it by hand and if you can follow the plot to here I suspect you can make the necessary allowances (there is a function to return the absolute value of a number if you wish to use that approach).