如何在开关语句后停止程序关闭
How to stop program from closing after switch statements
嗨,我目前正在制作一个带有四个选项菜单的基本程序。以下代码工作正常(我仍然需要对前三个选项进行工作,但我会尝试自己执行此操作)唯一的问题是在选择一个选项并且它破坏程序关闭之后。我想知道如何使程序在选择选项后返回菜单,并且程序仅在用户选择"4"时关闭。谢谢!
cout << "Correct login details entered!" << "" << endl;
cout << "1. Transfer an amount" <<endl;
cout << "2. List recent transactions"<<endl;
cout << "3. Display account details and current balance"<<endl;
cout << "4. Quit" << endl;
cout << "Please enter menu number"<<endl;
cin >> selection;
switch(selection)
{
case 1:
cout << "You have choosen to transfer an amount" << endl;
cout << "How much do you wish to transfer from the shop account?"<<endl;
cin >> B;
cout << B << endl;
break;
case 2:
cout << "Here are you're recent transactions" <<endl;
break;
case 3:
cout << "The account names is:" << name << endl;
cout << "The account number is:" << number << endl;
cout << "The current balance is" << endl; //Need to get cuurent balance still
break;
case 4:
return 0;
break;
default:
cout << "Ooops, invalid selection!" << endl;
break;
do{
cout << "Correct login details entered!" << "" << endl;
cout << "1. Transfer an amount" <<endl;
cout << "2. List recent transactions"<<endl;
cout << "3. Display account details and current balance"<<endl;
cout << "4. Quit" << endl;
cout << "Please enter menu number"<<endl;
cin >> selection;
switch(selection)
{
case 1:
//...
case 2:
//...
case 3:
//...
case 4:
//...
default:
//...
}
while(selection != 4);
while ( true )
{
cout << "1. Transfer an amount" <<endl;
// ...
switch(selection)
{
case 1:
// ...
} // end of switch
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- C++实用程序,用于将长开关语句转换为封装开关案例阶梯的简洁函数调用
- C++:如果用户输入数字将其转换为单词,并且如果按回车键程序应退出,则使用开关大小写
- 程序在开关中执行第二种情况后崩溃
- 退出程序,默认开关
- 程序编译,但我认为开关被忽略
- 开关大小写程序在某个点上保持循环.想不通
- 如何在开关语句后停止程序关闭
- 如何在不使用开关大小写的情况下用C++编写菜单驱动的程序
- 我应该继续使用 while 循环开关还是做一个问答程序,或者我应该使用开关
- 问关于 c++ 开关和 if 程序
- 在 Win 7 64 位下运行 32 位 Borland XE2 应用程序,带 /3gb 开关 (-GF LARGEAD
- 嵌套开关给出错误并指示病毒(特洛伊木马程序)
- C 使用 Y/N 选项循环开关。选择 N 不会关闭程序
- 开关基于协同程序