programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Tim Cooke
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Devaka Cooray
• Ron McLeod
• paul wheaton
Saloon Keepers:
• Tim Moores
• Piet Souris
• Tim Holloway
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Frits Walraven
• Scott Selikoff

# Error in calculation

Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
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

Rancher
Posts: 618
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:

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
• Number of slices to send:
Optional 'thank-you' note:
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

lowercase baba
Posts: 13081
67
• Number of slices to send:
Optional 'thank-you' note:
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.

 Let's go to the waterfront with this tiny ad: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising