![]() |
Help with a test score problem
Ive been trying to write a program that will ask for 5 test scores, give you the average of the scores and also the corresponding grade that goes with them, unfortunately the grade doesn't seem to post when called. Any help would be welcome.
Code:
import javax.swing.JOptionPane; //Needed for GUI |
are any of the grades posting? have you set break points to step through? i read through and nothing stands out as wrong- are there any exceptions? is the double grade displaying and just the char is not?
|
the only error is
C:\Desktop\avg_Score_Anderson.java:97: error: variable grade might not have been initialized return grade; ^ 1 error The only thing that does not post is the letter grade, the actual number grades and average of them all post correctly. Im not sure if the char is incorrect or if i just skipped a step with the public static double determineGrade(double Average) part of the code. Thanks again for any help. |
I am surprised it is letting you compile- I found it; errors out in C# :P
you function "determineGrade" is a double- yet you are expecting it to be a char, and you are trying to return a char- you can't implicitly convert a char to a double. also the variable grade is not necessarily getting initialized- well it is (as it is the end result of a set of if/elseif statements) but in C# anyways it doesn't know that for sure- I was able to modify it by changing all those if/elseif's to a switch and default returning 'E' for error. this also then eliminates the need for the variable grade- or you could set grade to a variable and then return it but it is redundant... Code:
char grade; |
ended up just removing the last else option and making it the letter F, and also changing the base of that statement to a char and seems to run perfect now.
Finished code for anyone interested and thanks for all the help. Code:
import javax.swing.JOptionPane; //Needed for GUI |
| All times are GMT +1. The time now is 05:03 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.