# Looping and I/O Stream

• 09-07-2001
Unregistered
Looping and I/O Stream
I need to write a program where the system calculates the average of ten floating point numbers and calculates the standard deviation. The user is to input ten numbers and he program is supposed to display the average and standard deviation. I was using a FOR Loop for the input of the numbers but am confused as to where I will do the calculation for standard deviation? Would I need to call a function for this? Can I store the values of each number and use an array to display them?
• 09-07-2001
Witch_King
Average is a laymans term and it does not make any sense when used in the same sentance as standard deviation. Is average supposed to be the arithmetic mean, the midrange, midpoint, mode, or median? Yes you have to store the input into variables. Also you will have to use some math functions to aid the standard deviation calculation, and yes the calcuation would be done in a function.
• 09-07-2001
Unregistered
Looping and I/O stream
The program I am to write is to find the average of ten numbers.
Also Show what the standard deviation is. The formula given is as follows:
Standard Deviation=sqrt(sum of squared values/10)

Sum of the squared values deviation is:

pow ((value1- average),2) + pow((value2-avg),2).......

Do I have to do int v1, v2, v3 ...... Until ten?
I tried it this way:

# define max 10
int count
for(count=0; count<max; count++)
{
cout<<"enter a number ";
cin>>num;

Should I put a function after cin to hold the values of the numbers?
• 09-07-2001
SilentStrike
I am pretty sure average always implies mean.

Use an array to do this.

const int NUM_ELEMENTS = 10;

//main, includes, etc

int count=0;
int numbers[NUM_ELEMENTS];
while (count < NUM_ELEMENTS]) {
cin >> numbers[count];
}

// use another loop to calculate average

// use yet another loop to calculate the standard deviation after the average is known