Class grades??

closed account (z6f9LyTq)
Write a C++ program that will calculate the average of each student, as well as the class average.

In a Loop, either a While, or Do/While you will input three test scores for each student. Output the student’s average, and then start with the next student.

I need help with this?? I only figured out how to do it with a FOR loop...

Create the code that produces the following output.

Input Section:

ENTER STUDENT #1’s - TEST SCORE NUMBER 1: ? 100

ENTER STUDENT #1’s - TEST SCORE NUMBER 2: ? 90

ENTER STUDENT #1’s - TEST SCORE NUMBER 3: ? 81

Output Section:
Test#1 Test#2 Test #3 Average

Student #1 100 90 81 90.33



(Note: One of these reports for each student)
closed account (L6b7X9L8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while(cin >> score1 >> score2 >> score 3)
{
    if(score1 == -1) break; //If first score = -1 break from the while loop, you are done.
    double average = ((score1 + score2 + score3) / 3) // Assuming each loop has only 3 test scores;
    cout << "Student #" << (int)StudentNumber << "\t" << score1 << " " << score2 << " " << score3 << " Avg: " << average;

    (double)StudentAverage[StudentNumber] = average; //Assumed there is a constant number of students

    StudentNumber++;
}

double ClassAverage = 0;

for(int i = 0; i < StudentMax; i++)
{
    ClassAverage += StudentAverage[i];
}

ClassAverage = ClassAverage / StudentMax;

cout << "Class average is: " << ClassAverage;


That's how I'd attempt it.
Last edited on
Topic archived. No new replies allowed.