0
How to force the user to choose switch statement in order?
Like how to let him choose case 1 before case 2 and if he choose case 2 before case 1 i want to say error but if he choose case 1 and the case 2 the switch statwment work
4 Réponses
+ 2
Add a variable naming isChooseOne = false. If user press 1 set isChooseOne = true. If user press 2 check isChooseOne variable. If isChoooseOne = false. Alert error message to user
C code:
bool isChoooseOne = false;
switch(keypress)
{
case keypress: "1"
isChooseOne = true;
break;
case keypress: "2"
if(!isChooseOne)
printf("error")
break;
}
+ 1
Instead of @, add language name in tag...
You mean to execute all cases sequentially..?
Give an example what you looking..!
0
In C
0
Store the last state in a variable, then you can check it in your switch case 2 and print error if last state is not 1