• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in calculation

 
Lucas Stelljes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I am working on a program to calculate the GPA of a student using a "While" Loop. I have the program written to near completion, and it runs, but I have an error.
Whenever I try to calculate the GPA, no matter how "high" or "low" the student's theoretical GPA should be, it always retains a result of 0.0. I am unable to figure out what I have mistyped/left out.

Can anyone help or suggest anything, or how to refine the program?
Thanks, Lucas

 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only set gpa in one place. When you calulate gpa, you divide qualPts by totalCredits. What happens if qualPts is zero? What happens if totalCredits is zero? Here's a suggestion. Everywhere you set qualPts to a value, print its value. Every where you set totalCredits, print its value. Is the output what you expect?
 
Lucas Stelljes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the quick reply.

So this is how I understand your comments: I need to define gpa in more then one place in order for it to "calculate" properly?

Also, I think I found my error. I have qualPts set = 0 at the beginning of the program. During the Loop when I try to calculate qualPts again, I multiply (numgrade + credits)*qualPts. Am I getting a 0.0 for my gpa calculation because it's being multiplied by 0, thus gaining a net result of 0?

Thanks,
-Lucas
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this is how I understand your comments: I need to define gpa in more then one place in order for it to "calculate" properly?

No. I pointed out "one place" so that you recognise there is only one place that could set gpa to zero.
Also, I think I found my error. I have qualPts set = 0 at the beginning of the program. During the Loop when I try to calculate qualPts again, I multiply (numgrade + credits)*qualPts. Am I getting a 0.0 for my gpa calculation because it's being multiplied by 0, thus gaining a net result of 0?

That's one possibility. Another is that (numgrade + credits) sums to zero. Try adding more print statements to see which is correct.
 
Lucas Stelljes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found out that it's my assignment of "double qualPts = 0" that is resulting in the 0.0 GPA result.

What do I have to do to change this? I thought about creating a "private static double" method, but didn't think it was necessary. Is it, or is something else required?

-Lucas
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12101
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is 'qualPts' supposed to represent? I can't tell from your code or the variable name what it is supposed to be. perhaps you need to initialize it to something other than 1?

Perhaps you need an if statement in there to do something different if it is equal to zero?

What would your 'private static double' method DO exactly?

Tell us in English (not java) what this variable represents, and how you are supposed to calculate it, and perhaps we can give you better guidance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic