Re: GPA calc code... HELP
You're constructor's not quite right. You need to initialize it the the values inputted, not just to 0.
Re: GPA calc code... HELP
Re: GPA calc code... HELP
Oh wait, no, that's not a problem. I see what it is you're doing. hmm... I don't understand why you're getting the results you are. It seems to me that you should be getting A's almost all the time because you keep adding to grades, and never find an average grade.
This should work:
Code :
public void addGrade(double x)
{
grade = grade * numTest + x;
numTest++;
grade /= numTest;
if (grade >= 90)
{
gpa = 4;
}
else if (grade >= 80)
{
gpa = 3;
}
else if (grade >= 70)
{
gpa = 2;
}
else if (grade >= 60)
{
gpa = 1;
}
else
{
gpa = 0;
}
}