Overview: I need to make a program that lets a teacher enter grades on a test and then calculate the class average. The teacher is able to enter as many grades as they want and then enter -1 to stop. So far, my code does all of this but here's the second part of the program that I'm struggling with. I need to modify the program above to keep track of how many students received each letter grade on the exam and display the result along with the class average. So here's my go at it:
public void Grading2(){
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int f = 0;
int grade = 0;
int users = 0;
int all = 0;
double average = 0;
Scanner entry = new Scanner (System.in);
while (grade != -1){
// User enters their grades and then enters -1 to get the average
System.out.println("Enter your grades: ");
grade = entry.nextInt();
users = users + 1;
all = all + grade;
}
average = (all+1)/(users-1);
System.out.println("Your average is: " + average);
if (grade >= 90){
a++;
}
if (grade >= 80){
b++;
}
if (grade >= 70){
c++;
}
if (grade >= 60){
d++;
}
else if (grade <= 60){
f++;
}
}
Aucun commentaire:
Enregistrer un commentaire