当前位置:编程学习 > C/C++ >>

我的C/C++之路-007课(模仿ATM取款程序)

下面模仿下ATM取款机,有钱真好!!!

输入密码正确后可以:取款,存款,退出

[cpp]
#include<stdio.h> 
/*
模仿ATM取款程序
*/ 
int strCompare(char *,char *); 
int accountVerify(); 
void accountOperate(); 
 
void simulateOfATM() 

    if(accountVerify()) 
        accountOperate(); 
    printf("GOODBYE\n"); 

//不使用自带的strcmp,自己写个玩玩 
int strCompare(char *str1,char *str2) 

    while(*str1&&*str2&&(*str1==*str2)) 
    //while(*str1!='\0'&&*str2!='\0'&&(*str1==*str2))//这个效率低点,不过容易理解 
    { 
        str1++; 
        str2++; 
    } 
    return *str1-*str2; 

//通行验证  www.zzzyk.com
int accountVerify() 

    char password[50];//我就不信你们的密码超过50, 30倒是见过 
    char pwd[10]={"abc"}; 
    int pwdCount=0;//记录密码输入次数,不能超过3次 
    do{ 
        printf("please input your password or press ENTER to break: \n"); 
        gets(password); 
        if(!strCompare(password,"\0")){ 
            break; 
        } 
        if(strCompare(password,pwd)){//密码错误 
            printf("PASSWORD ERROR !!!\n"); 
            pwdCount++; 
        } 
        else 
        { 
                return 1; 
        } 
     
    }while(pwdCount<3); 
    if(pwdCount>=3) 
        printf("input count has outnumber,good bye!!\n");//输入超过限制 
    else printf("GOODBYE\n"); 
    return 0; 

//账户操作 
void accountOperate() 

    int operate,initMoney=100;//初始账户值:100 
    int oprateMoney = 0;//操作金额数 
    do{ 
        printf("the amount of your card is:  %d\n",initMoney); 
        printf("*********** ACCOUNT OPERATE***************\n"); 
        printf("*          1: get money                  *\n"); 
        printf("*          2: deposite                   *\n"); 
        printf("*          3: exit                       *\n"); 
        printf("******************************************\n"); 
        printf("please select a operate: "); 
        scanf("%1d",&operate); 
        switch(operate) 
        { 
        case 1: 
            printf("how much whould you like to get: "); 
            scanf("%d",&oprateMoney); 
            if(oprateMoney<=0||oprateMoney>initMoney)//如果输入金额小于等于0或者大于账户余额 
            { 
                printf("输入错误或者余额不足!!\n"); 
                continue; 
            } 
            initMoney -= oprateMoney; 
            printf("¥%d 正在吐钞,请笑纳………\n",oprateMoney); 
            continue; 
        case 2: 
            printf("how much whould you like to put: "); 
            scanf("%d",&oprateMoney); 
            initMoney += oprateMoney; 
            printf("press any key to go back"); 
            continue; 
        case 3: 
        default: 
            return; 
        } 
    }while(1); 


摘自 mzlqh的专栏
补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,