can you choose more than one case in a switch statement?
Or, how can you choose witch dice to keep in a dice game?
Say you roll five dice and you need to keep 3 at different places in your array of dice?
@katielynnsdad:
I understood only the first question. And the answer to that is 'yes'. It is possible to execute more than one cases in a switch statement. In the switch statement, once a case condition is met, the execution flow continues till it sees a break statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
switch(i)
{
case 1:
case 2:
printf(" 1 or 2 ");
break;
case 3:
case 4:
printf(" 3 or 4 ");
break;
case 5:
case 6:
printf(" 5 or 6");
break;
default:
printf("i is some thing other than 1,2,3,4,5 and 6.");
}