| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 465 人关注过本帖
标题:ATM模拟系统代码错误分析。求改正
只看楼主 加入收藏
kang211
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2010-10-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
ATM模拟系统代码错误分析。求改正
在做一个ATM模拟系统,要求必须实现多用户注册,用户信息写入txt文件,并且可调出,现在我只会写入,不会调出,所以没用写入,可是为什么这样不能实现多用户?希望指点!
#include<stdio.h>
#include<sys\stat.h>
#include<fcntl.h>
#include<io.h>
#include<windows.h>
#include<string.h>
#include<stdlib.h>
void menu()
{
    printf("\n\t**********************欢迎使用ATM系统***************************\n\n\n");
    printf("                  1、添加账户\n");
    printf("                  2、存款\n");
    printf("                  3、取款\n");
    printf("                  4、余额查询\n");
    printf("                  5、退出\n");
}

struct information
{
    char name[20];
    char num[10];
    char password[8];
    char sex[10];
    char adds[40];
    int money;
}xx[100];
int isCorrect(char *an,char *psd)
{
    int i;
    for(i=0;i<100;i++)
    {
    if(strcmp(xx[i].name,an)==0 && strcmp(psd,xx[i].password)==0)
        return 1;
    }
  return 0;
}
void add()
{
               
}
int main()
{
     char ch[100],you[20],youm[10];
     int amount,errorcount=0,i,a=0;
     int handle;
     char s[1000];
     
     int length,res;
     for(;;)
     {
        menu();
        printf("     请选择:");
        scanf("%s",ch);
        if(strcmp(ch,"1")==0)
          {
                system("cls");
                for(;a<100;a++)
           {
           printf("\n请输入用户名:");
           scanf("%s",xx[a].name);
           printf("\n请输入账号:");
           scanf("%s",xx[a].num);
           printf("\n请输入密码:");
           scanf("%s",xx[a].password);getchar();
           printf("\n请输入存款金额:");
           scanf("%d",&xx[a].money);getchar();
           printf("\n请输入性别:");
           scanf("%s",xx[a].sex);getchar();
           printf("\n请输入地址:");
           scanf("%s",xx[a].adds);
           printf("\n\t\t\t恭喜你注册成功\n");
           /*sprintf(s,"%s %s %s %d %s %s",xx[a].name,xx[a].num,xx[a].password,xx[a].money,xx[a].sex,xx[a].adds);
           printf("%s",s);
           if((handle=open("yonghu.txt",O_WRONLY))==-1)
           {
             printf("Error opening file.\n");
             exit(1);
           }
           length=strlen(s);
           lseek(handle,0,SEEK_END);
           if((res=write(handle,s,length))!=length)
           {
             printf("Error writing to the file.\n");
             exit(1);
           }*/
           getchar();getchar();break;
                }system("cls");
          }
        else if(strcmp(ch,"2")==0)
          {
           system("cls");
           printf("请输入你的账户名:");
           scanf("%s",you);getchar();
           printf("请输入你的密码:");
           scanf("%s",youm);
           for(i=0;i<100;i++)
           {
           if(isCorrect(you,youm)==1)
             {
              printf("请输入您的存款金额:");
              scanf("%d",&amount);
              xx[i].money=xx[i].money+amount;
              printf("存款成功!您的当前余额为:%d元\n",xx[i].money);break;
             }
           else
             {
              errorcount++;
              
              if(errorcount==3)
               {
                printf("您已经连续三次输入错误,系统将自动关闭\n");goto C;
               }printf("密码或用户名错误\n");break;
           }
           }
           getchar();getchar();system("cls");
          }
      else if(strcmp(ch,"3")==0)
         {
           system("cls");
           printf("请输入你的账户名:");
           scanf("%s",you);getchar();
           printf("请输入你的密码:");
           scanf("%s",youm);
           for(i=0;i<100;i++)
           {
           if(isCorrect(you,youm)==1)
           {
              printf("请输入您的取款金额:");
              scanf("%d",&amount);
              if(amount<=xx[i].money)
                {
                    xx[i].money=xx[i].money-amount;
                    printf("取款成功!您的当前余额为:%d元\n",xx[i].money);break;
               }
              else
                {
                  printf("账户余额不足、取款失败!\n");break;
                }
           }
           else
          {
           errorcount++;
              if(errorcount==3)
           {
             printf("您已经连续三次输入错误,系统将自动关闭\n");goto C;
           }
              printf("密码或用户名错误\n");break;
           }
           }
           getchar();getchar();system("cls");
         }
      else if(strcmp(ch,"4")==0)
         {                  
           system("cls");
           printf("请输入你的账户名:");
           scanf("%s",you);getchar();
           printf("请输入你的密码:");
           scanf("%s",youm);
           for(i=0;i<100;i++)
           {
           if(isCorrect(you,youm)==1)
           {
               printf("您现在的余额为%d元\n",xx[i].money);break;
           }
           else
             {
              errorcount++;
              if(errorcount==3)
                {
                 printf("您已经连续三次输入错误,系统将自动关闭\n");goto C;
                }
              printf("密码或用户名错误\n");break;

           }
           }
           getchar();getchar();system("cls");
         }
      else if(strcmp(ch,"5")==0)
                {
        C:system("cls");
        printf("\n\n    ***********************************************\n");
        printf("\t**\t\t\t\t**\n");
        printf("\t**\t谢谢使用\t\t**\n");
        printf("\t**\t  再见  \t\t**\n");
        printf("\t**\t\t\t\t**\n");
        printf("    ***********************************************\n");
        
        getchar();getchar();return;
           }
              
else
{
system("cls");
 }
}
getchar();getchar();
return 0;
}
搜索更多相关主题的帖子: 用户 
2011-01-15 17:45
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:20 
牛啊,都写ATM机了
2011-01-19 08:50
快速回复:ATM模拟系统代码错误分析。求改正
数据加载中...
 
   



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

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