The
switch
statement doesn't allow for multiple conditions, it only allows for case when the
switch
variable value exactly matches that specified in the
case
block.
You need to use
if ... else if ... else
instead:
if (a <= 100 && a >= 80)
{
...
}
else if (a >= 50)
{
...
}
else
{
...
}
If your tutor has told you to use a
switch
and nothing else, then subtract one from the percentage (to bring all the values in to a range 20 to 39 instead of 21 to 40) then
switch
on that value divided by ten.
That will reduce it to 9
case
statements and a default if you think about it for a minute or two.
Give it a try - it's not complicated!