| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2166 人关注过本帖
标题:大佬求改bug。周日中午前DDL
取消只看楼主 加入收藏
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
大佬求改bug。周日中午前DDL



#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include <iostream>
#include <windows.h>

int count=0;

//定义结构体
struct logistics
{
    char name[20];
    char code[6];
    char ID[18];
    int money;
    int num;
};

//用户主界面
int UI_main()
{
    printf("                                                        **************************************\n");
    printf("                                                        *      欢迎使用银行ATM存取款系统     *\n");
    printf("                                                        **************************************\n");
    printf("\n");
    printf("                                                                 1.开户\n");
    printf("                                                                 2.登录\n");
    printf("                                                                 0.退出\n");
    printf("                                                             请输入你的选择,回车确认;\n");
    return 100;
}

//开户
int inputinformation()
{
    printf("                                                        **************************************\n");
    printf("                                                        *            欢迎使用开户系统        *\n");
    printf("                                                        **************************************\n");
    printf("\n");
    FILE *fp;
    logistics input;
    fp = fopen("information.dat", "a+");
    if (fp == NULL)
    {
        printf("文件打开失败。");
        return 0;
    }
    else
    {
        char code[6];
        printf("                                                                 请输入姓名\n");
        scanf("%s", &input.name);
        printf("                                                                请输入身份证号\n");
        scanf("%s", &input.ID);
        input.money = 0;
        count++;
        input.num = count;
        while (1)
        {
            printf("                                                                 请输入密码\n");
            scanf("%s ", &input.code);
            printf("                                                                请再次输入密码\n");
            scanf("%s ", &code);
            if (strcmp(input.code, code) == 0)
            {

                fwrite(&input, sizeof(logistics), 1, fp);
                printf("                                                                   开户成功,您的账户是%s", input.ID);
                break;
            }
            else
            {
                printf("                                                              两次密码不一致请重新输入");
                system("pause");
                system("CLS");
            }
        }
    }
    fclose(fp);

    return 1;
}

//登录
int login()
{
    printf("                                                        **************************************\n");
    printf("                                                        *      欢迎登录银行ATM存取款系统     *\n");
    printf("                                                        **************************************\n");
    printf("\n");
    FILE *fp1;
    logistics login;
    char n[18];
    char m[6];
    printf("                                                                 请输入您的账户\n");
    scanf("%s", &n);
    printf("\n");
    if ((fp1 = fopen("information.dat", "r")) != NULL)
    {
        rewind(fp1);
        fread(&login, sizeof(login), 1, fp1);

        while (!feof(fp1))
        {

            if (strcmp(login.ID, n)==0)
            {
                while(1)
                {
                    printf("                                                   请输入密码\n");
                    scanf("%s", &m);
                    if (strcmp(login.code, m) == 0)
                    {
                        printf("                                               登录成功");
                        break;
                    }
                    else
                    {
                        printf("                                               密码错误");
                        system("CLS");
                    }

                }
               
            }
            fread(&login, sizeof(login), 1, fp1);
            
        }
    }
    else
    {
        printf("cannot open the file\n");
        return 0;
    }

    fclose(fp1);
    return login.num;
}

//业务菜单
void UI_next()
{
    printf("                                                        **************************************\n");
    printf("                                                        *            请选择您的业务          *\n");
    printf("                                                        **************************************\n");
    printf("\n");
    printf("                                                                     1.存款\n");
    printf("                                                                     2.取款\n");
    printf("                                                                     3.转账\n");
    printf("                                                                     4.查询\n");
    printf("                                                                     5.修改密码\n");
    printf("                                                                     0.退出\n\n");
   
}

//查询
int search()
{
    FILE *fp1;
    logistics find;
    char n[18];
    printf("请输入您的账户\n");
    scanf("%s", &n);
    printf("\n");
    if ((fp1 = fopen("information.dat", "r")) != NULL)
    {
        rewind(fp1);
        fread(&find, sizeof(find), 1, fp1);

        while (!feof(fp1))
        {

            if (strcmp(find.ID,n)==0)
            {
                printf("您的账户是\n");
                printf("%s\n", find.ID);
                printf("您当前账户余额为\n");
                printf("%d\n", find.money);
                system("pause");

            }

            fread(&find, sizeof(find), 1, fp1);
        }
        return 1;

    }
    else
    {
        printf("cannot open the file\n");
        return 0;
    }

    fclose(fp1);
}

//存款
int again(int admin)
{
    int  b = 0, n = 0, i = 0,a = 0;
    FILE *fp;
    logistics chang[999];
    fp = fopen("information.dat", "r+");
    if (fp == NULL)
    {
        printf("无法打开\n");
        return 0;
    }

    a = admin;
    rewind(fp);
    while (!feof(fp))
    {
        fread(&chang[i], sizeof(logistics), 1, fp);
        n++;
        if (chang[i].num== a )
        {
            printf("请放入存款\n");
            scanf("%d", &b);
            chang[i].money = chang[i].money + b;
            break;

        }
        else
        {
            fclose(fp);
            return 0;
        }
    }
    i++;

    fp = fopen("information.dat", "r+");
    for (i = 0; i < n; i++)
    {

        fwrite(&chang[i], sizeof(logistics), 1, fp);
    }


    fclose(fp);
    return 0;
}

//取款
int take(int admin)
{
    int  b = 0, n = 0, i = 0, a = 0,c=0;
    FILE *fp;
    logistics chang[999];
    fp = fopen("information.dat", "r+");
    if (fp == NULL)
    {
        printf("无法打开\n");
        return 0;
    }

    a = admin;
    rewind(fp);
    while (!feof(fp))
    {
        fread(&chang[i], sizeof(logistics), 1, fp);
        n++;
        if (chang[i].num == a)
        {
            printf("请输入取款金额\n");
            scanf("%d", &b);
            c = chang[i].money - b;
            if (c > 0)
            {
                printf("取款成功");
                chang[i].money = c;
                break;
            }
            else
            {
                printf("余额不足");
                fclose(fp);
                return 0;

            }
        }
        else
        {
            fclose(fp);
            return 0;
        }
    }
    i++;

    fp = fopen("information.dat", "r+");
    for (i = 0; i < n; i++)
    {

        fwrite(&chang[i], sizeof(logistics), 1, fp);
    }


    fclose(fp);
    return 1;
}

//转账
int bring(int admin)
{
    int  b = 0, n = 0, i = 0, a = 0, c = 0;
    FILE *fp;
    logistics chang[999];
    fp = fopen("information.dat", "r+");
    if (fp == NULL)
    {
        printf("无法打开\n");
        return 0;
    }

    a = admin;
    rewind(fp);
    while (!feof(fp))
    {
        fread(&chang[i], sizeof(logistics), 1, fp);
        n++;
        if (chang[i].num == a)
        {
            printf("请输入转账金额\n");
            scanf("%d", &b);
            c = chang[i].money - b;
            if (c > 0)
            {
                FILE *fp1;
                logistics find;
                char n[18];
                printf("请输入转账用户帐号\n");
                scanf("%s", &n);
                printf("\n");
                if ((fp1 = fopen("information.dat", "r")) != NULL)
                {
                    rewind(fp1);
                    fread(&find, sizeof(find), 1, fp1);

                    while (!feof(fp))
                    {

                        if (strcmp(find.ID,n)==0)
                        {
                            find.money = find.money + b;
                        }

                        fread(&find, sizeof(find), 1, fp1);
                    }
                    printf("转账成功");
                    chang[i].money = c;
                    break;
                }
                else
                {
                    printf("余额不足");
                    fclose(fp);
                    return 0;

                }
            }
            else
            {
                fclose(fp);
                return 0;
            }
        }
        i++;

        fp = fopen("information.dat", "r+");
        for (i = 0; i < n; i++)
        {

            fwrite(&chang[i], sizeof(logistics), 1, fp);
        }


        fclose(fp);
        return 1;
    }
    return 1;
}

//更改密码
int change(int admin)
{
    int   n = 0, i = 0, a = 0;
    char b[6];
    FILE *fp;
    logistics chang[999];
    fp = fopen("information.dat", "r+");
    if (fp == NULL)
    {
        printf("无法打开\n");
        return 0;
    }

    a = admin;
    rewind(fp);
    while (!feof(fp))
    {
        fread(&chang[i], sizeof(logistics), 1, fp);
        n++;
        if (chang[i].num == a)
        {
            while (1)
            {
                printf("                                                                 请输入密码\n");
                scanf("%s ", &chang[i].code);
                printf("                                                                请再次输入密码\n");
                scanf("%s ", &b);
                if (strcmp(chang[i].code, b) == 0)
                {

                    fwrite(&chang[i], sizeof(logistics), 1, fp);
                    printf("                                                                   更改成功");
                    break;
                }
                else
                {
                    printf("                                                              两次密码不一致请重新输入");
                    system("CLS");
                }
            }
            break;

        }
        else
        {
            fclose(fp);
            return 0;
        }
    }
    i++;

    fp = fopen("information.dat", "r+");
    for (i = 0; i < n; i++)
    {

        fwrite(&chang[i], sizeof(logistics), 1, fp);
    }


    fclose(fp);
    return 0;
}

int main()
{
    UI_main();
    int pos = -1,admin=0,poe=-1;
    scanf("%d", &pos);
    fflush(stdin);
    while (pos != 10)
    {
        switch (pos)
        {
        case 1:inputinformation();
            break;
        case 2:
        
            admin = login();
            if (admin != 0)
            {
                UI_next();
                scanf("%d", &poe);
                while (poe != 10)
                {
                    switch (poe)
                    {
                    case 1:again(admin);
                        break;
                    case 2:take(admin);
                        break;
                    case 3:bring(admin);
                        break;
                    case 4:search();
                        break;
                    case 5:change(admin);
                        break;
                    case 0:exit(0);
                        break;
                    default:
                        printf("输入信息有误,请重新输入。\n");
                    }

                    system("pause");
                    system("CLS");

                    UI_next();
                    scanf("%d", &poe);
                    system("CLS");
                }
            }
        
            else
            {
                break;
            }
            break;
        case 0:exit(0);
            break;
        default:
            printf("输入信息有误,请重新输入。\n");
        }
        system("pause");
        system("CLS");

        UI_main();
        scanf("%d", &pos);
        system("CLS");
    }
}



[此贴子已经被作者于2017-9-24 11:27编辑过]

搜索更多相关主题的帖子: int printf return scanf break 
2017-09-23 19:22
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
收藏
得分:0 
回复 2楼 yu965634383
东大的啊,这个运行有bug……
不要照抄啊,给条活路
2017-09-24 00:07
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
收藏
得分:0 
回复 4楼 炎天
两点了睡不着上来看看,居然有大佬回信!语言已经不能描述我内心此刻的激动了!!!
真的,真的,真的得非常感谢!
这些问题我会一行一行照着看的,真的是,非常感谢!
试着运行了一下,发现查询那里好像显不出来,我会试着改改看,总觉得弄明白这个题我就朝着远离小白的方向迈出了一大步!
最后,再次奉上我真诚的祝福,大佬一生幸福平安!
2017-09-24 01:59
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
收藏
得分:0 
回复 8楼 炎天
可能是我C++的版本太低,就是在查询那里输入账户后,直接跳转到上一级页面,没有显出账户信息。
2017-09-24 11:26
快速回复:大佬求改bug。周日中午前DDL
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028348 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved