急,C语言小白,拼凑了一个ATM小程序却不会改,求大佬帮忙
题目是做一个ATM的存取款系统,要能开户、登录、存款、取款、查询、转账、修改密码……(开户用身份证号开户)
求大佬帮忙整理修改一下,已经快写疯了……
(最好格式能统一一下)
各位大佬的大恩大德,小女子一定会铭记在心
#include<stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
struct information
{
char name[20];
char ID[18];
char code[6];
int money;
struct information *next;
}
main() //主菜单
{
int i;
while (1)
{
printf("*************************\n");
printf("欢迎使用银行ATM存取款系统\n");
printf("*************************\n");
printf("1、开户\n");
printf("2、登录\n");
printf("3、退出\n");
printf("请选择\n");
scanf("%d", &i);
switch (i)
{
case 1:printf("欢迎进入开户系统\n");
open();
break;
case 2:login();
break;
case 3:break;
default:printf("输入错误,无法执行\n");
}
if (i == 3)break;
};
}
void open(struct information *head) //开户
{
int n=0;
char choose;
struct information *head;
struct information *p1, *p2;
void save(struct information *);
p1=p2=(struct information *)malloc(LEN);
printf("请输入姓名:");
scanf("%s", p1->name);
printf("请输入身份证号:");
scanf("%s", p1->ID);
printf("请输入密码:");
scanf("%s", p1->code);
printf("您的账户是");
puts(ID);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct information *)malloc(LEN);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请输入身份证号:");
scanf("%s",p1->ID);
printf("请输入密码:");
scanf("%s",p1->code);
printf("您的账户是");
puts(ID);
}
p2->next=NULL;
printf("是否保存以上数信息?请输入y或n\n");
scanf("%c",&choose);
scanf("%c",&choose);
while (1)
{
if (choose=='y')
{
save(head);
break; }
else if (choose=='n')break;
else printf("输入错误,请重新输入!\n");
scanf("%c",&choose);
}
return 0;
}
void account(struct information *head) //储存信息
{
struct information *p;
FILE *fp;
p=head;
fp=fopen("D:\\account.txt","a");
do
{
fprintf(fp,"%s%s%s",p->name,p->ID,p->code);
p=p->next;
} while (p!=NULL);
fclose(fp);
}
void login(struct information *head) //登录
{
char ID[18];
char code[6];
int i,j;
FILE *fp
information *p1,*p2;
if((fp=fopen("account.txt","rb+"))==NULL)
{
printf("没有该账户信息\n");
}
p1=(information*)malloc(sizeof(LEN));
head=p1;
while(!feof(fp))
{
if(1!=fread(p,sizeof(information),1,fp))
break;
p1->next=(information *)malloc(sizeof(information));
p2=p1;
p1=p1->next;
}
p2->next=NULL;
fclose(fp);
printf("欢迎进入登录系统\n");
for(j=1;j<4;j++)
{
printf("请您输入账户\n");
scanf("%s",d);
for(p2=head;p2!=NULL;p2=p2->next)
{
if(strcmp(p2->ID,d)!=0)
{
continue;
}
else
{
for(i=1;i<4;i++)
{
printf("请输入您的密码\n");
scanf("%s",code);
if(strcmp(p2->code,code)!=0)
{
printf("\n密码不正确,请重新输入密码\n");
system("pause");
system("cls");
continue;
}
else
{
system("cls");
menu(head);
}
}
printf("\n您输入密码三次错误,谢谢光临\n");
system("pause");
system("cls");
exit(0);
}
}
printf("\n您输入的账户有误,请重试\n");
system("pause");
system("cls");
}
printf("您的账户三次输入错误,谢谢使用");
exit(0);
}
void menu(struct information *head) //菜单
{
head=NULL;
int i;
printf("请选择您的业务:\n\n");
printf("1.存款\n");
printf("2.取款\n");
prinrf("3.查询\n");
printf("4.转账\n");
printf("5.修改密码\n");
printf("6.退出\n\n");
printf("请选择\n\n");
scanf("%d",&i);
swich(i)
{
case 1:deposit();
system("cls");
break;
case 2:withdrawal();
system("cls");
break;
case 3:find();
system("cls");
break;
case 4:transfer();
system("cls");
break;
case 5:modify();
system("cls");
break;
case 6:break;
system("cls");
default:
printf("输入错误,无法执行\n\n");
system("pause");
system("cls");
}
if(i==6)break;
}
void deposit(struct information *head) //存款
{
struct information *p;
FILE *fp;
p=head;
printf("请将存款放入存款处\n");
printf("确认并继续\n");
scanf("%d",&b)
fp=fopen("D:\\account.txt", "a");
do
{
fprintf(fp,"%d",p->money);
p=p->next;
} while (p!=NULL);
fclose(fp);
}
void withdraw(struct information *head) //取款
{
head=NULL;
information *p;
FILE *fp;
fp=fopen("Daccount.txt","wb+");
printf("请输入您的取款金额:");
scanf("%d",&m);
if(m>information.money)
{
printf("对不起,您的余额已不足\n");
printf("请重新输入\n");
scanf("%d",&m);
}
else{
information.money=information.money-m;
if(fwrite(money,sizeof(information),1,fp)!=1)
printf("file write error\n");
printf("您的当前余额为:\n");
printf("%d",information.money);
}
fclose(fp);
}
void find(struct information *head) //查询
{
head=NULL;
information *p;
FILE *fp;
fp=fopen("account.txt","rb+");
p=(information*)malloc(sizeof(information));
fread(p,sizeof(information),1,fp);
printf("您的当前余额为:%d/n",p->money);
system("pause");
system("cls");
fclose(fp);
}
void transfer(struct information *head) //转账
{
head=NULL;
information *p;
FILE *fp;
fp=fopen("account.txt","rb+");
p=(information*)malloc(sizeof(information));
fread(p,sizeof(information),1,fp);
fclose(fp);
int i,j,k;
printf("请输入转账账户\n");
scanf("%d",&i);
printf("请再次输入转账账户\n");
scanf("%d",&j);
if(i!=j)
{
printf("两次账户不相同,请重新输入\n");
transfer(head);
}
else
{
system("cls");
printf("请输入转账金额\n");
scanf("%d",&k);
k=k*100;
if(k>p->money)
{
printf("对不起,您的余额已不足\n");
system("pause");
system("cls");
caidan(head);
}
else
{
printf("您已成功转账%d元\n",k);
p->money-=k;
if((fp=fopen("accunt.txt","wb+"))==NULL)
{
printf("cannot open file\n");
return;
}
if(fwrite(p,sizeof(information),1,fp)!=1)
printf("file write error\n");
p->next=NULL;
fclose(fp);
p->next=NULL;
system("pause");
system("cls");
}
}
}
}
void modify(struct information *head) //修改密码
{
int x=0,i=0,n=0,m=0,t;
char code2[6],code3[6];
printf("请输入原始密码:");
scanf("%d",&code2);
if(strcmp(code2,code)==0)
{
do {
printf("请输入新密码:");
scanf("%s",password);
printf("请再次输入您的新密码:");
scanf("%s",newly);
if(strcmp(password,newly)==0)
{printf("修改成功!\n");m=0;}
else{
printf("两次输入密码不同,请重新设置密码!\n");
n=1;}
}
while(n==1);
x=1;
}
if (x==0){
printf("原始密码不正确!请重新输入!\n");
m=1;i++;}
if(i==3){
printf("您已三次输入密码不正确!请稍后再试!\n");break;}
}
while(m==1);
}