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

20th Nov 2020, 5:51 PM
Abada Aroub
Abada Aroub - avatar
4 Answers
+ 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; }
20th Nov 2020, 6:09 PM
Toan Phan
+ 1
Instead of @, add language name in tag... You mean to execute all cases sequentially..? Give an example what you looking..!
20th Nov 2020, 6:03 PM
Jayakrishna 🇼🇳
0
In C
20th Nov 2020, 5:51 PM
Abada Aroub
Abada Aroub - avatar
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
20th Nov 2020, 6:06 PM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar