在做任何事情之前退出基本的银行程序

Basic bank program exiting before doing anything

本文关键字:程序 退出 任何事      更新时间:2023-10-16

我尝试过调试,它似乎在int main之后的大括号之前停止。有人能帮我们找到一个解决方案并解释为什么它不起作用吗。

#include <iostream>
#include <string>
using namespace std;
enum Menusystem  // enum is a function used to convert the list of words below
                 // into numbers.
{
  ShowMenu,
  EnterName,
  Account,
  Deposit,
  Withdraw,
  Balance,
  Exit
} menu;
int main() {
  string customer;  // declaring variables and their data types for the menu
                    // options.
  string accounttype;
  string name;
  int credit;
  int debit;
  int currentbal;
  bool exit = false;  // declaring variable as boolean setting it to false so
                      // that when the loop gets to true it will break the loop.
  int option = 0;  // declares showmenu as a integer and sets value to 0 so that
                   // the menu will be displayed upon opening the program as in
                   // the code below the menu is displayed if option is equal to
                   // 0.
  while (!Exit)  // declares that if the exit button has not been pressed the
                 // application will stay open.
  {
    switch (menu)  // initiates a switch statement which will allow the program
                   // to cycle through menu options depending on the menu option
                   // they select.
    {
      case ShowMenu:
        cout << "[0] - Show menun"  // displays menu options to user.
             << "[1] - Enter Full Namen"
             << "[2] - Enter Account Typen"
             << "[3] - Deposit Fundsn"
             << "[4] - Withdraw Fundsn"
             << "[5] - Display Balancen"
             << "[6] - Exit Programn";
        cin >> option;
        if (option == 0)
          menu = ShowMenu;
        else if (option == 1)
          menu = EnterName;
        else if (option == 2)
          menu = Account;
        else if (option == 3)
          menu = Deposit;
        else if (option == 4)
          menu = Withdraw;
        else if (option == 5)
          menu = Balance;
        else if (option == 6)
          menu = Exit;
        else
          menu = ShowMenu;  // default case is to show the menu.
        break;
      case EnterName:
        cout << "Please enter your full name >n";
        getline(cin, name);
        menu = ShowMenu;
        break;
      case Account:
        menu = ShowMenu;
        break;
      case Deposit:
        menu = ShowMenu;
        break;
      case Withdraw:
        menu = ShowMenu;
        break;
      case Balance:
        menu = ShowMenu;
        break;
      case Exit:
        menu = ShowMenu;
        break;
      default:
        break;
    }
  }
}

更换

while (!Exit)

while (!exit)

此行是while (false)循环

while(!Exit)