如何在开关语句后停止程序关闭

How to stop program from closing after switch statements

本文关键字:程序 开关 语句      更新时间:2023-10-16

嗨,我目前正在制作一个带有四个选项菜单的基本程序。以下代码工作正常(我仍然需要对前三个选项进行工作,但我会尝试自己执行此操作)唯一的问题是在选择一个选项并且它破坏程序关闭之后。我想知道如何使程序在选择选项后返回菜单,并且程序仅在用户选择"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
}