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!
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace 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;
}