| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2164 人关注过本帖
标题:大佬求改bug。周日中午前DDL
只看楼主 加入收藏
tszxmr
Rank: 1
等 级:新手上路
帖 子:1
专家分:5
注 册:2017-9-24
收藏
得分:5 
以下是引用炎天在2017-9-24 00:40:16的发言:

字符串输入不用加&, 类似scanf("%s", str);,  scanf("%s这里不要加无用的空格,当然你要占一个位置的话你就加一个空格", ...);
还有一些其他的地方

#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[16];
    char ID[20];
    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", "ab+");
    if (fp == NULL)
    {
        printf("文件打开失败。");
        return 0;
    }
    else
    {
        char code[16];
        printf("                                                                 请输入姓名 和 自定义账户(身份证号)\n");
        scanf("%s", input.name);    //字符串不用加&
        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);
    Sleep(1400);
    return 1;
}

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

        int flag = 0;
        while (!feof(fp1))
        {
            fread(&login, sizeof(logistics), 1, fp1);
            if (strcmp(login.ID, n) == 0)
            {
                while (1)
                {
                    printf("                                                   请输入密码\n");
                    scanf("%s", m);           //字符串不用加&
                    if (strcmp(login.code, m) == 0)
                    {
                        printf("                                               登录成功");
                        flag = 1;
                        break;
                    }
                    else
                    {
                        printf("                                               密码错误");
                        system("CLS");
                    }

                }

            }
            //fread(&login, sizeof(logistics), 1, fp1);
            if (flag == 1)
            {
                break;
            }

        }
    }
    else
    {
        printf("cannot open the file\n");
        return 0;
    }
    printf("\n登录中...");
    Sleep(800);
    fclose(fp1);
    fflush(stdin);
    system("cls");

    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()
{
    system("cls");
    FILE *fp1;
    logistics find;
    char n[18];
    printf("请输入您的账户\n");
    scanf("%s", n);
    printf("\n");
    if ((fp1 = fopen("information.dat", "rb")) != NULL)
    {
        rewind(fp1);
        fread(&find, sizeof(logistics), 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;
    }
    printf("\n页面跳转中...");
    Sleep(1000);
    fclose(fp1);
}

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

    a = admin;

    rewind(fp);
    fread(&chang, sizeof(logistics), 1, fp);
    while (!feof(fp))
    {

        n++;
        if (chang.num == a)
        {
            printf("请放入存款\n");
            scanf("%d", &b);
            chang.money = chang.money + b;
            break;

        }

        i++;
        fread(&chang, sizeof(logistics), 1, fp);
    }

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

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

    fclose(fp);
    printf("\n存款中...");
    Sleep(1000);
    return 0;
}

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

膜拜~
2017-09-24 12:04
Laurel123
Rank: 1
等 级:新手上路
帖 子:1
专家分:5
注 册:2017-9-6
收藏
得分:5 
那个iostream是什么啊
2017-09-24 15:28
快速回复:大佬求改bug。周日中午前DDL
数据加载中...
 
   



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

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