So here I am writing this code and I am having problems with something basic, but I think I am overlooking something simple. Reading a text file I had to come up with arithmetic sum and root-mean-square average. the arithmetic sum is fine but the root-square-mean isn't correct because after the first while loop i can't change it.

Code:

Code:

-4.1 -2.2 -0.5 1.2 3.3 4.6 5.1 2.1 0.2 -3.6 -4.1 0.2
0.5 2.2 4.1 -0.2 -1.2 -3.3 -4.6 -5.0 -2.2 -1.1 0.8 3.2
-0.1 -4.8

And here is the Code

Code:

Code:

/* Christopher R Smith
COMP1200 - Fall 2008
Assignment 6
Program: Average Value Program
-------------------------------------------------------------------------------------------------------------
Taking surface measurements from a text file, compute and display the Arithmetic Mean Value, the
Root Mean Square Average, and the Max Roughness Height
--------------------------------------------------------------------------------------------------------------
*/
#include <stdio.h>
#include <math.h>
int main()
{
FILE *inp;
double value,
mean,
root_mean_square,
sum=0,
max_height;
int numValue=0,
count;
inp = fopen("surface.txt", "r");
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
{
sum += fabs(value);
numValue++;
}
mean = sum / numValue;
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
{
sum += pow( fabs(value), 2 );
numValue++;
}
root_mean_square = sqrt( sum / numValue);
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
{
double max=-10000, min=10000;
if (value >= max)
max = value;
else
min = value;
;
max_height = max - min
}
printf( "Arithmetic mean value %.2lf\n", mean);
printf( "Root-mean-square average %.2lf\n", root_mean_square);
printf( "Maximum roughness height %.2lf\n", max_height);
return (0);
}

i am getting

Code:

64.500000
Arithmetic mean value 2.48
Root-mean-square average 1.58
Maximum roughness height 1889828851749420549890302903237191694835027000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00

No matter what I do to

Code:

while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
sum =+ pow ( (fabs(value)), 5);

I can't manipulate the sum , it stays at 64.5000000 from the first calculation in

Code:

while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
{
sum += fabs(value);
numValue++;
}
mean = sum / numValue;