繁体   English   中英

c++ atm菜单驱动程序程序

[英]c++ program for atm menu driven program

#include <iostream>
#include <conio.h>
using namespace std;
void showmenu()
{
    cout << "***menu***" << endl;
    cout << " enter 1  to   checkbalance" << endl;
    cout << " enter 2  to   deposit" << endl;
    cout << " enter 3  to  withdraw" << endl;
    cout << ":::::::::::::::::::::::::::::::::::::";
}

int main()
{
    int option;
    double balance = 500;
    double deposit, withdraw;
    do {
        showmenu();
        cout << "option";
        cin >> option;
        switch (option)
        {
            case1: cout << "balance is" << balance << endl;
            break;
            case2: cout << "  enter deposit amount";
            cin >> deposit;
            balance += deposit;
            break;
            case3: cout << "withdraw amount";
            cin >> withdraw;
            if (withdraw <= balance)
            {
                balance -= withdraw;
            }
            else
            {
                cout << "insufficient amount";
                break;
            }
        }
    } while (option != 4);
    return 0;
    getch();
}

当我运行这段代码时,我得到的是此处可用选项的迭代。它似乎是一个简单的代码,但我受够了这些简单的错误并努力纠正它。帮助我

我认为您忘记在关键字 case 和案例编号之间放置空格。 我做了一些小改动。 更正后的代码:

#include <conio.h>
#include <iostream>

using namespace std; 

void showmenu() {   
    cout<<"menu"<<endl; 
    cout<<" enter 1 to checkbalance"<<endl; 
    cout<<" enter 2 to deposit"<<endl; 
    cout<<" enter 3 to withdraw"<<endl; 
    cout<<":::::::::::::::::::::::::::::::::::::"<<endl;
} 

int main() {    
    int option; 
    double balance=500; 
    double deposit,withdraw; 
    do{ 
        showmenu(); 
        cout<<"option"; 
        cin>>option; 
        switch(option) {    
            case 1:
                cout<<"balance is"<<balance<<endl; 
                break; 
            case 2:
                cout<<" enter deposit amount"; 
                cin>>deposit; 
                balance+=deposit; 
                break; 
            case 3:
                cout<<"withdraw amount"; 
                cin>>withdraw; 
                if(withdraw<=balance) {     
                    balance-=withdraw;
                } else {    
                    cout<<"insufficient amount"; 
                }
                break;
            
        } 
        
    }while(option!=4);
    getch();
    return 0; 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM