在做任何事之前退出的基本银行计划

时间:2014-04-26 15:06:59

标签: c++

我已经尝试过调试,它似乎在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 menu\n"  // displays menu options to user.
             << "[1] - Enter Full Name\n"
             << "[2] - Enter Account Type\n"
             << "[3] - Deposit Funds\n"
             << "[4] - Withdraw Funds\n"
             << "[5] - Display Balance\n"
             << "[6] - Exit Program\n";

        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;
    }
  }
}

2 个答案:

答案 0 :(得分:1)

替换

while (!Exit)

使用

while (!exit)

答案 1 :(得分:0)

此行是while (false)循环

  

while(!退出)