fsdfsfw
2021-10-07 16:24
采纳率: 100%
浏览 23

有没有人可以告诉我这串代码问题在哪?

有没有大 佬解释一下啊,这是我打的ATM取款机的程序


#include<iostream>
#include<string>
using namespace std;
struct user
{
    string name;
    int ID;
    int passport;
    int money=0;
};
struct user a[1000];
void zhuce()//注册
{
    cout << "输入你要注册的10位ID" << endl;
    int iid; cin >> iid;
    a[iid].ID = iid;
    cout << "输入你要注册的密码" << endl;
    int iid1; cin >> iid1;
    a[iid].passport = iid1;
    cout << "输入您的名字" << endl;
    string iid2; cin >> iid2;
    a[iid].name = iid2;
}
void show()//显示用户信息
{
    cout << "输入ID" << endl;
    int id;
    cin >> id;
    flag1:
    cout << "输入密码" << endl;
    int m;
    cin >> m;
    if (m == a[id].passport)
    {
        cout << "欢迎使用" << endl;
        cout << "ID:" << a[id].ID
            << "\nMONEY:" << a[id].money << endl;
    }
    else
    {
        cout << "error" << endl;
        goto flag1;
    }
}
void change1()//修改密码
{
    cout << "输入ID" << endl;
    int id;
    cin >> id;
flag1:
    cout << "输入密码" << endl;
    int m;
    cin >> m;
    if (m == a[id].passport)
    {
        cout << "欢迎使用" << endl;
    flag2:
        cout << "输入密码" << endl;
        int m;
        cin >> m;
        if (m == a[id].passport)
        {
            cout << "输入新密码" << endl;
            int nm;
            cin >> nm;
            a[id].passport = nm;
        }
        else
        {
            cout << "error" << endl;
            goto flag2;
        }
    }
    else
    {
        cout << "error" << endl;
        goto flag1;
    }
}
void cun()//存款
{

    cout << "输入ID" << endl;
    int id;
    cin >> id;
flag1:
    cout << "输入密码" << endl;
    int m;
    cin >> m;
    if (m == a[id].passport)
    {
        cout << "欢迎使用" << endl;
        cout << "ID:" << a[id].ID
            << "\nMONEY:" << a[id].money << endl;
        cout << "请输入存款金额" << endl;
        int nm; cin >> nm;
        a[id].money += nm;
    }
    else
    {
        cout << "error" << endl;
        goto flag1;
    }
}
void ti()//提款
{
    cout << "输入ID" << endl;
    int id;
    cin >> id;
flag1:
    cout << "输入密码" << endl;
    int m;
    cin >> m;
    if (m == a[id].passport)
    {
        cout << "欢迎使用" << endl;
        cout << "ID:" << a[id].ID
            << "\nMONEY:" << a[id].money << endl;
        cout << "请输入存款金额" << endl;
        int nm1; cin >> nm1;
        a[id].money -= nm1;
    }
    else
    {
        cout << "error" << endl;
        goto flag1;
    }
}
int main()
{
    int a;
    while (1)
    {
        cout << "****ATM system****" << endl
            << "****1.查询账户****" << endl
            << "****2.修改密码****" << endl
            << "******3.存款******" << endl
            << "******4.取款******" << endl
            << "****5.注册账户****" << endl
            << "****0.退出系统****" << endl;
        cin >> a;
        switch (a)
        {
        case 1:
            void show();
        case 2:
            void change1();
        case 3:
            void cun();
        case 4:
            void ti();
        case 5:
            void zhuce();
        case 0:
            goto flag;//退出
        default:
            break;
        }
        system("cls");
    }
    flag:
    cout << "Thank you for using";
    return 0;
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题