大佬求改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编辑过]