Loop Help -- Averaging numbers

Hey everyone. I've got this program here that averages student test scores. Right now it only calculates average score per student. I want it to do that AND calculate the class average. How would I get the program to add up each student's average and divide by the number of students in each class? Thanks for any help!

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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	int numStudents,  // Number of students
		numTests;     // Number of tests per student
	double total,     // Accumulate for total scores
		average;      // Average test score

					  // Setup numeric output formatting
	cout << fixed << showpoint << setprecision(1);

	// Get the number of classes.
	int numClasses;
	const string classMessage = "How many classes are there? ";
	cout << "This program averages test scores.  \n";
	cout << classMessage;
	cin >> numClasses;
	while (numClasses < 1 || numClasses > 3) 
	{
		cout << "ERROR. Must enter 1, 2, or 3." << endl;
		cout << classMessage;
		cin >> numClasses;
	}
	for (int classn = 1; classn <= numClasses; classn++)
	{
		int totalC = 0;
		for (int testc = 1; testc <= numClasses; testc++)
		{
			int classnumber;
			cout << "What class do you want to average? (Class 1, 2, or 3) Class: "; // Class 1, 2, or 3?
			cin >> classnumber;

			// Get the number of students.
			cout << "For how many students do you have scores in this class? ";
			cin >> numStudents;

			// Get the number of test scores per student.
			cout << "How many test scores does each student have? ";
			cin >> numTests;

			// Determine each student's average score.
			for (int student = 1; student <= numStudents; student++)
			{
				total = 0;  // Initialize the accumulator.
				for (int test = 1; test <= numTests; test++)
				{
					double score;
					cout << "Enter score " << test << " for ";
					cout << "student " << student << ": ";
					cin >> score;
					total += score;
				}
				average = total / numTests;
				cout << "The average score for student " << student;
				cout << " is " << average << ". \n\n";
				system("pause");
			}
		}
	}

	return 0;
}
just like you would on paper. Everytime you get a average for a student, add that to classTotal and add 1 to numberStudents.
Topic archived. No new replies allowed.