I am trying to calculate 3 things from a data file using functions , I think something is wrong in main() because I not returning the right results
What do you guys think?
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>
double rMeanValue ( double sumA, double value);
double rSqAve (double sumS, double value);
double rMaxHeight (double max, double min);
int main()
{
FILE *inp;
double value,
mean,
root_mean_square,
max_height=0,
max,
min,
sumA=0,
sumB=0;
inp = fopen("surface.txt", "r");
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
mean = rMeanValue( sumA, value);
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
root_mean_square = rSqAve ( sumB, value);
while ( ( fscanf ( inp,"%lf", &value ) ) == 1 )
max_height = rMaxHeight (max, min);
fclose(inp);
printf( "Arithmetic mean value = %.2lf\n", mean);
printf( "Root-mean-square average = %.2lf\n", root_mean_square);
printf( "Maximum roughness height = %.1lf\n", max_height);
return(0);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
double rMeanValue ( double sum, double value)
{
double numValue1,
mean;
sum += fabs(value);
numValue1++;
mean = sum / numValue1;
return mean;
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
double rSqAve (double sum, double value)
{
double numValue2,
root_mean_square;
sum =sum + pow(value,2);
numValue2++;
root_mean_square = sqrt( (sum / numValue2) );
return root_mean_square;
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
double rMaxHeight (double max, double min)
{
double value,
Max_Height;
if (value >= max)
max = value;
if (value <= min)
min = value;
Max_Height = max-min;
return Max_Height;
}