(si - a)2
for each score, where
a
is the average and si
is the value of
the i-th score. You then take the sum of the results of this computation and
divide by 4 (the sample size). Then take the square root of that result to get the standard deviation. See
this Wikipedia article
for the full equation for computing standard deviation and an example of
estimating standard deviation from a sample.
Your get_input() function will read the integers from a file, lab6.dat. You can copy this file to your current directory on Helios with the command:
cp /usr/users/mdanfor/public_html/cs221-f06/lab6.dat .For this particular problem, using the arrow operators (fin >> num1 for example) to read the entire file would be better suited. Refer to your notes from Wednes. lecture or Chapter 6 in the book.
This is your main function. You will need to define the prototypes and bodies for get_input(), average() and std_dev().
int main() { int num1, num2, num3, num4; double avg, std; get_input(num1, num2, num3, num4); avg = average(num1, num2, num3, num4); std = std_dev(num1, num2, num3, num4); printf("The average is %.2f and the standard deviation is %.2f.\n", avg, std); return 0; }
#ifdef DEBUG_ME printf("**DEBUG** read in from file: %d %d %d %d\n", num1, num2, num3, num4); #endifAlso add a debugging statement to std_dev() that prints out the value of
(si - a)2
for each score. Remember you will
need to add #define DEBUG_ME
at the top of your program (in the
global scope) and recompile to see the debugging messages.