Array/Calculation Help

I am having a hard time understanding what exactly is wrong with my code and why my output file isn't correct. I will post the assignment I need to do below and also the code I have written under it. Thanks for any help guys, and please keep is beginner I am still not understanding very complex code yet.

Assignment:

The three roughness indicators are:
Arithemetic mean value:
Ra = (|a| + |b| + |c| + ....) / n

Root-mean-square average:
Rq = sqrt[( a^2 + b^2 + c^2 + ...)/n]

Maximum roughness height:
hmax = distance from the bottom of deepest trough to top of highest peak


Instructions:
Write a modularized C++ program that does the following:

Reads data from the input file called surface.txt.
This file looks like the one shown below. It contains the roughness data for a particular sample. Calculates the three roughness parameters. Generates a report.

This report should be in a file that looks like the output shown below.
Notes:

Roughness Data File
Data values are in micrometers
-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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  #include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <math.h>

using namespace std;

const int SIZE = 100;

void readData (double data[], int& numbers);
void calcData (double data[], int numbers, double& arithMean, double& rootMean, double& maxHeight);
void printReport (double data[], int numbers, double arithMean, double rootMean, double maxHeight);

int main()
{
	double maxHeight, data[SIZE], arithMean, rootMean;
	int numbers;

	readData (data, numbers);
	calcData (data, numbers, arithMean, rootMean, maxHeight);
	printReport (data, numbers, arithMean, rootMean, maxHeight);

	return 0;
}

void readData (double data[], int& numbers)
{
	ifstream inputFile;

	inputFile.open("surface.txt");

	if (inputFile.fail())
	{
		cout <<"Error opening input file: " <<"surface.txt, file may not be in the correct location.";
		exit(1);
	}
	inputFile >> numbers;

	for (int i = 0; i < numbers; i++)
	{
		inputFile >> data[i];
	}
	inputFile.close();

	return;
}

void calcData (double data[], int numbers, double& arithMean, double& rootMean, double& maxHeight)
{
	double sum = 0;

	maxHeight = data[0];
	for (int i=1; i<numbers; i++)
	{
		if (data[i] > maxHeight)
			maxHeight = data[i];
	}

	for (int i = 0; i< numbers; i++)
		{
			sum += fabs(data[i]);
		}

	arithMean = sum/numbers;


	for (int i = 0; i< numbers; i++)
	{
	rootMean = sqrt (pow (data[i], 2)/numbers);
	}
			return;
}

void printReport (double data[], int numbers, double arithMean, double rootMean, double maxHeight)
{
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(2);

	ofstream outputFile;
	outputFile.open("Roughness.txt");

	outputFile <<"Surface Roughness Data" <<endl;
	for (int i = 0; i< numbers; i++)
	{
		outputFile << data[i]<<"µm"<<endl;
		cout << data[i]<<"µm"<<endl;
	}

	outputFile <<"Arithmetic Mean = " << arithMean <<" µm"<<endl;
	cout <<"Arithmetic Mean = " << arithMean <<" µm"<<endl;

	outputFile <<"Root-Mean Square = " <<rootMean <<" µm"<<endl;
	cout <<"Root-Mean Square = " <<rootMean <<" µm"<<endl;

	outputFile <<"Maximum Roughness = " <<maxHeight <<" µm"<<endl;
	cout <<"Maximum Roughness = " <<maxHeight <<" µm"<<endl;

	outputFile.close();
	return;

}




Also I wanted to set the floating point for the file output but I do not know how to do that. I tried copying and using cout but changing it to outputFil.set etc but that didn't work. Thanks for the help, and this forum has been a tremendous benefit to me!
Topic archived. No new replies allowed.