multiple averages into an existing array

I have a program that should find the average of each row and then input into the existing array filled with student scores. I have the code for finding the averages...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void findAverage(ofstream &outFile, float testScores[][maxCol], int &row)
{
	float total;
	float average;
	int i, j;
	for (i = 0; i < row; i++)
	{
		total = 0;
		for (j = 0; j < 4; j++)
		total += testScores[i][j];
		average = total / 4;
	}
return;
}


But from there how do I input the "average" variable into the last column of an array.
My print may be incorrect as well. The max number of test scores is known (4), but I should assume that up to 50 students may be on the data file. In order to first show the data without the average and then with the average will I need two seperate print functions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void printData (ofstream &outFile, int studID[], float testScores[][maxCol], int &row, int &col)
{
	// GIVEN: 
	// TASK: 
	// RETURNS: 

	int i, j;
	for (i = 0; i < row; i++)
	{
		outFile << setw(7) << studID[i];
		for (j = 0; j < 4; j++)
		{
			outFile << setw(13) << fixed << setprecision(2) << testScores[i][j];
		}
		outFile << endl;
	}
return;
}
One way is to declare an array as 2 dimensions of say 10 rows and 5 columns. Make sure every row ends with a blank or 0. That is every fifth element in each row is a '0' or space. Now with a loop average the 1st 4 elements in each row and place that value in the fifth column of each row.
Topic archived. No new replies allowed.