Hi
In this code I have tried to substitute the if else statement between line 80 and 107 which I commented out, for a switch case statement. It is however not working the way it should when I compile it. I would greatly appreciate any advice. Thank you.
true is a constant expression and is always 1... So it will always fall under your case 1 label. This is why your code did not work.
However, I don't think in this case you can convert the if and else (especially with the else ifs) to a switch. Reason being that switch checks for an exact match (==), while in your ifs you have >=. You might have to look for another way to break the number down if you want to use a switch.
Look at the syntax of the switch statement between lines 29 and 45:
1 2 3 4
switch( /*char or int type variable*/ ) {
case /* char or int RValue */ : // Do stuff if the variable being switched equals the RValue specified
default: // Do this if no case is met
}
The conditional is built into the switch statement and you are trying to specify your own, which you cannot do.