| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1630 人关注过本帖
标题:急,C语言小白,拼凑了一个ATM小程序却不会改,求大佬帮忙
只看楼主 加入收藏
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:6 
急,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);
       }
搜索更多相关主题的帖子: printf scanf 输入 head system 
2017-09-20 18:03
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
收藏
得分:0 
有人在吗……江湖救急
2017-09-20 18:06
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10541
专家分:42927
注 册:2014-5-20
收藏
得分:5 
你写的这个程序觉得哪里有问题?
2017-09-20 19:45
Cxiao白
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-9-20
收藏
得分:0 
回复 3楼 吹水佬
哪里都是问题・_・?
因为根本不会用链表……
从一开始那个开户就写的不对
2017-09-21 08:37
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10541
专家分:42927
注 册:2014-5-20
收藏
得分:0 
以下是引用Cxiao白在2017-9-21 08:37:09的发言:

哪里都是问题・_・?
因为根本不会用链表……
从一开始那个开户就写的不对

都是问题・_・?
写了那么多代码,佩服还能写下去。
那就先说说“从一开始那个开户就写的不对”的问题
2017-09-21 10:02
从入门到入坟
Rank: 2
等 级:论坛游民
帖 子:17
专家分:15
注 册:2017-9-20
收藏
得分:5 
这是天书啊。。
2017-09-21 17:26
yu965634383
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:119
专家分:195
注 册:2017-9-1
收藏
得分:5 
这个急不来的,需要耐心。你的那个程序我觉得只要弄懂了链表和文件的基本操作基本可以写出来了。所以你必须要把链表的一些基本操作弄清楚。

菜鸟一枚,求各位大神多多关照。
2017-09-21 21:14
快速回复:急,C语言小白,拼凑了一个ATM小程序却不会改,求大佬帮忙
数据加载中...
 
   



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

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