I have a switch statement that takes the letter grade and returns the corresponding GPA; however, it throws a cannot-find-symbol error for the letters (A, B, C, D & F)! I’ve checked the javaDocs for guidance but couldn’t find something wrong. What is causing this error?
switch (grade) {
case A: nv[i] = 4; //nv = numerical value
break;
case B: nv[i] = 3;
break;
case C: nv[i] = 2;
break;
case D: nv[i] = 1;
break;
case F: nv[i] = 0;
break;
}
Aisn’t a valid character literal –'A'is.So you want:
You should also probably have a default case for situations where the grade isn’t one of those.
Oh, and your code could also be written as:
with a check for
nv[i]being -1 afterwards (meaning that the grade wasn’t in that set).