c++ help

Ok I have been given an assignment in which I must write a program which asks for the number of students in a class, which you then enter (and it must be between 1 and 5) and then the number of quizzes which the students have taken (same number as before) and you input both of those. then it asks you to enter the name of each student and the score of each quiz they have taken. it will calculate the average, print the quiz average, and tell you the grade for each student.
this is my code so far:

#include <cstdlib>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;

int main()
{
int x, y, quizzes;
int students = 0;
int sum = 0;
int average;
string studentName;

cout << "Type in the number of students: ";
cin >> x;
if (x > 1 && x < 5)
{
cout << "Enter the number of quizzes the students have taken: ";
cin >> y;
int array[y];
if ( y > 1 && y < 5)
{
do
{
cout << "Enter the student's name: \n";
cin >> studentName;
for ( quizzes = 0; quizzes < y; quizzes++ )
{
cout << "Enter the quiz scores for " << studentName << ": ";
cin >> array[quizzes];
sum = sum + array[quizzes];
}
average = sum / y;
if (average >= 90)
cout << "For " << studentName << " the average quiz score is: " << average << " and their grade is an A." << endl;
else if (average < 90 && average >= 80 )
cout << "For " << studentName << " the average quiz score is: " << average << " and their grade is a B." << endl;
else if (average < 80 && average >= 70 )
cout << "For " << studentName << " the average quiz score is: " << average << " and their grade is a C." << endl;
else if (average < 70 && average >= 60 )
cout << "For " << studentName << " the average quiz score is: " << average << " and their grade is a D." << endl;
else
cout << "For " << studentName << " the average quiz score is: " << average << " and their grade is an F." << endl;
students++;
}while ( students != x);
}

}
}


the problem i am having is that each time you enter the quiz scores for a student, it adds together any previous quiz scores also entered, and finds the average of all scores for all students, rather than for each individual student. any help that could be given would be appreciated.
and beyond that one problem, everything runs perfectly. i've tried various combinations of code to fix it, however nothing i've attempted works.
Yes, it's because of sum = sum + array[quizzes]; if you could have reset sum to zero after average = sum / y;, I hope your problem would have been solved!

EDIT: And oh!, b4 I 4get, plz use code tags next time you're posting a code.

Thanks,
Aceix.
Last edited on
thank you.

and sorry about that, I'm new to this website.
Topic archived. No new replies allowed.