A
isn’t a valid character literal – 'A'
is.
So you want:
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;
}
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:
nv[i] = "FDCBA".indexOf(grade);
with a check for nv[i]
being -1 afterwards (meaning that the grade wasn’t in that set).
3
solved Switch statement (Character) [closed]