So here I am writing this code and I am having problems with something basic, but I think I am overlooking something simple. I am trying to read from a text file and compute mean, root mean, and Max height (which is the highest number - lowest number) It's coming up with some huge number so yea, I need a second opinion please! Here is the data file
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:
/* 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);
}
This problem is probably coming from this segment of code
Code:
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
{
double max=-10000, min=10000;
if (value >= max)
max = value;
else
min = value;
;
max_height = max - min
}
I am receiving this output
Code:
Arithmetic mean value 2.48
Root-mean-square average 1.58
Maximum roughness height 1889828851749420549890302903237191694835027000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00
Is that huge number some other value somewhere else in the computer