在a++中返回菜单选择
Return to a menu choice in A++
这是一个很难的问题,我已经看到了这个问题的答案,但这些答案对于像我这样的新手来说还不够愚蠢。所以,我的问题是,如果我进入一个菜单,选择一个选项,完成那个选项,然后我需要回到主菜单去做另一个选项,有人能用菜鸟术语解释吗?谢谢。
一个例子:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout << "Main Menu:" << endl;
cout << "01. This Option" << endl;
cout << "02. Another Option" << endl;
int option;
cin >> option;
if(option==1)
{
//do stuff and then go back somehow
}
if(option==2)
{
//do other stuff and come back somehow
}
else
{
cout << "INVALID!" << endl;
system("Pause");
return 0;
}
}
引入一个循环。
#include <iostream>
#include <cstdlib> //this is needed to use the function system
//#include <windows.h> //not used here
using namespace std;
int main()
{
for(;;) //infinite loop
{
cout << "Main Menu:" << endl;
cout << "01. This Option" << endl;
cout << "02. Another Option" << endl;
int option;
cin >> option;
if(option==1)
{
//do stuff and then go back somehow
}
else if(option==2) // else should be here, or the program will end when option==1
{
//do other stuff and come back somehow
}
else
{
cout << "INVALID!" << endl;
system("Pause");
return 0;
}
}
}
相关文章:
- 无法获取菜单选择以运行函数.C++
- 带有选择的菜单列表
- 菜单选择器不接受有效输入
- 我如何制作用户可以选择的菜单
- Windows Shell 扩展:当选择超过 16 个文件时,上下文菜单
- 在菜单前键入字符串后,C 如何从菜单中选择选项
- C++ 如何实现带有数字和字母选择的菜单
- 如何强制用户在从菜单中选择之前输入一些数字
- IFstream在选择菜单选项后无法打开文件
- 用户从菜单 C++ 中选择数组类型
- 如何检查菜单中的哪个项目被选中?如何通过选择菜单项发送int/wxstring
- 操作菜单按钮选择bb10
- Linux上基于C++文本的选择菜单的行为很奇怪
- 以编程方式检索上下文菜单的选择
- 在a++中返回菜单选择
- 用c++编写一个菜单程序,让用户从选项列表中进行选择,如果输入的不是其中一个选项,则重新打印该列表
- 通过选择"退出"菜单项关闭应用程序 - wxWidgets 3.0
- C++循环一个菜单,直到选择了所有选项
- 切换不打开的箱子,通过返回菜单功能获得选择
- QT上下文菜单只在QTreeView选择