标题:为什么文件中会有0出现?密码也修改不了?
只看楼主
狗砸
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-1-8
结帖率:0
已结贴  问题点数:20 回复次数:1 
为什么文件中会有0出现?密码也修改不了?
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define N 200

void enterATM();        //账号输入
void inputMima();       //密码输入
void menu();            //主界面
void Debit();           //取款
void success();         //操作成功
void zhuan();           //转账
void Quary();           //余额查询
void Credit();          //存款
void panDuan(double z); //判断取款是否合法
void Exit();            //退出界面
void miMa();            //密码修改
void read();            //文件写入
void write();           //文件读取

typedef struct
{
    int zhanghao;
    int mima;
    double yu_e;
}atm;
atm ATM[N];
int k;

//ATM账号输入
void enterATM()
{
    int user;
    system("cls");
    read();
    printf("欢迎光临中国银行网上银行\n");
    printf("请输入九位数银行卡号\n");
   
    scanf("%d",&user);
    if(user==0)
    {
        printf("该卡号不存在\n");
        enterATM();
    }
    else if(user!=(ATM[k].zhanghao))
    {
    for(k=1;k<N;k++)
    {
    if(user==(ATM[k].zhanghao))
        inputMima( );
    }
    system("cls");
    printf("输入错误\n");
    enterATM();
    }
    else
    inputMima( );
}

//密码输入
void inputMima( )
{
    int m[7],n;
    int j=3;
    read();
    system("cls");
    printf("请输入六位数密码\n");
loop:        while(1)
    {
for(n=0;n<6;n++)
    {
            m[n]=getch();
            printf("*");
        }
m[n]='\0';
            
        
    if(m[7]=ATM[k].mima)
    menu();
    else
    {
    j--;
        system("cls");
        printf("密码错误,请重新输入\n");
        printf("您还有 ");
        printf("%d",j);
        printf(" 次机会\n");
if(j==1)

{printf("密码输入3次错误,卡已被吞!");
exit(0);
}
            goto loop;
   
    }
            }   
}
//取款
void Debit()
{
    double temp;
    system("cls");
    printf("     请选择您要取款的金额     \n");
    printf("        1.100    2.200        \n");
    printf("        3.500    4.800        \n");
    printf("        5.1000   6.其它       \n");
    printf("        7.返回   8.退出       \n");
    switch(getch())
    {
    case '1': panDuan(100);
        break;
    case '2': panDuan(200);
        break;
    case '3': panDuan(500);
        break;
    case '4': panDuan(800);
        break;
    case '5': panDuan(1000);
        break;
    case '6':
        system("cls");
        printf("请输入您要取款的金额:");
        scanf("%lf",&temp);
        panDuan(temp);
        break;
    case '7':menu();
        break;
    case '8':Exit();
        break;
    }
}

//余额查询
void Quary()
{

    system("cls");
    printf("你的余额为:%lf\n",(ATM[k].yu_e));
    printf("1.返回      2.退出     \n");
    switch(getch())
    {
    case '1': menu();
        break;
    case '2': Exit();
        break;
    }
}

//判断取款是否合法
void panDuan(double z)
{
    int b;
    if(z>(ATM[k].yu_e))
    {
        system("cls");
        printf("           余额不足!         \n");
        printf("          请重新操作          \n");
        printf("     1.返回       2.退出      \n");
        switch(getch())
        {
        case '1': Debit();
        case '2': Exit();
        }
    }
    b=(int)z%100;
    if(b!=0)
    {
        system("cls");
   
        printf("  本ATM机只支持 100 的人民币  \n");
        printf("           请重新操作         \n");
        printf("                              \n");
        printf("     1.返回        2.退出     \n");
        switch(getch())
        {
        case '1': Debit();
        case '2': Exit();
        }
    }
    if(z==10000.00||z>10000.00)
    {
        system("cls");
        printf("    每次取款不能超过 10000 元  \n");
        printf("           请重新操作         \n");
   
        printf("     1.返回        2.退出     \n");
        switch(getch())
        {
        case '1': Debit();
        case '2': Exit();
        }
    }
    (ATM[k].yu_e)-=z;
    write();
    success();
}

//存款
void Credit( )
{
    double c;
    system("cls");
    printf(" 请放入人民币:");
    scanf("%lf",&c);
    while(c<0)
    {
        system("cls");
        printf("            非法存款          \n");
        printf("        请重新放入人民币      \n");
        scanf("%lf",&c);
    }
    (ATM[k].yu_e)+=c;
    write();
    success();
}

//转账
void zhuan()
{   
    int e,user;
system("cls");
printf("请输入要转账的卡号:\n");
    scanf("%d",&user);
    if(user==(ATM[k].zhanghao))
        printf("请输入你要转账的金额:");
    scanf("%d",&e);
                        if (e>(ATM[k].yu_e))
                        printf("输入错误\n");
                    else
                    {
                (ATM[k].yu_e)+=e;
                    write();
    success();
                    }
   
}


//密码修改
void miMa()
{
    int n,ch[7],m[7];
    int temp;

    system("cls");
 puts("请输入需要修改的密码\n");
                for(n=0;n<6;n++)
                {
                    ch[n]=getch();
                printf("*");
            }
                printf("\n");
                printf("请确认修改密码\n");
for(n=0;n<6;n++)
                {
                    m[n]=getch();
                printf("*");
            }
                printf("\n");
    if(strcmp(ch,m)==0)
    {
        ATM[k].mima=m;
        write();
        success();
    }
    else
    {
                    printf("选择错误,重新选择\n");
menu();
    }
}

//操作成功
void success( )
{
    system("cls");
    printf("           操作已成功         \n");

    printf("     1.返回        2.退出     \n");
    switch(getch())
    {
    case '1':menu();
        break;
    case '2':Exit();
        break;
    }
}

//系统退出函数
void Exit()
{
    system("cls");

    printf("         系统正在退出...      \n");
exit(0);
}

//文件读取函数
void read()
{
    int i;
    FILE *fp;
    fp=fopen("in.txt","r");
    if(fp==NULL)
    {
        printf("打开文件失败\n");
        return;
    }
    for(i=0;i<N;i++)
    {
        
        fscanf(fp,"%d",&(ATM[i].zhanghao));
        fscanf(fp,"%d",&(ATM[i].mima));
        fscanf(fp,"%lf\n",&(ATM[i].yu_e));
    }
    fclose(fp);
}

//文件写入函数
void write()
{
    int i;
    FILE *fp;
    fp=fopen("in.txt","w");
    if(fp==NULL)
    {
        printf("打开文件失败\n");
        return;
    }
    for(i=0;i<N;i++)
    {
        fprintf(fp,"%d",ATM[i].zhanghao);
        fprintf(fp,"%d",ATM[i].mima);
        fprintf(fp,"%lf\n",ATM[i].yu_e);
    }
    fclose(fp);
}

//主操作界面函数
void menu( )
{
    system("cls");
   
    printf("         请选择一下业务       \n");
    printf("          1.修改密码          \n");
    printf("          2.余额查询          \n");
    printf("          3.取款              \n");
    printf("          4.存款              \n");
    printf("          5.转账              \n");
    printf("          6.退出              \n");

    switch(getch())
    {
    case '1': miMa();
        break;
    case '2': Quary();
        break;
    case '3': Debit();
        break;
    case '4': Credit();
        break;
case '5': zhuan();
        break;

    case '6': Exit();
        break;
    default:
        {
            printf("非法操作\n");
            menu();
        };
    }
}

//主函数
void main()
{
    enterATM();
}


附:123456789 123456 9600.000000
987654321 654321 29000.000000
搜索更多相关主题的帖子: void atm printf case break 
2018-01-08 20:34
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
得分:20 
else if(user!=(ATM[k].zhanghao))
enterATM里面,这个k不是还没有值吗?
2018-01-09 11:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-484084-1-1.html




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

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