如何在C中的开关盒中返回使用盒的菜单 [英] How to go back to menu using case in switch case in C
本文介绍了如何在C中的开关盒中返回使用盒的菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在不使用GOTO命令的情况下,如何在切换情况下使用情况返回菜单.这是示例:
How to go back to menu using case in switch case without using GOTO command. So this is the sample:
while(1){
printf("1: Basic Math\n2. Intermediate Math\n3. Advance Math");
printf("Enter your choice: ");
int choice;
scanf("%d", &choice);
switch(choice)
int theChoices;
case 1:
printf("1. Add\n 2. Subtract\n3. Go back to menu");
scanf("%d", &theChoices);
switch (theChoices) {
case 1:
//calculation ...
case 2:
//calculation ...
case 3:
// Go Back to menu which is Basic math, Intermediate Math, Advance math
// ***** I want to know how do i get back to the main menu. *****
case 2:
// ....
// ....................
所以我的问题又是我如何使用情况3返回菜单.当我尝试使用关键字break时,当我选择情况3时它将自动关闭程序.
So my question again is how do i get back to the menu using the case 3. When i try using the keyword break, it automatically close the program when i chose case 3. Please help.
推荐答案
请改用continue;
.它将跳出所有case
并继续在它们之后执行代码,这将使程序返回到while (1)
之后的第一行.不要忘记用break;
关闭每个case
.
Use continue;
instead. It will jump out of all case
s and continue executing code after them, which will make the program return to the first line after while (1)
. Don't forget to close each case
with a break;
.
这篇关于如何在C中的开关盒中返回使用盒的菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文