zoukankan      html  css  js  c++  java
  • C语言模拟ATM机界面

    虽然是满屏的printf、printf、printf、printf、、、、、、尴尬

    但是一个小项目做下来还是能学习到很多的,有很多小的问题,不是亲自来敲一遍代码,是不会发现的。他的框架,每一个小函数功能的实现,

    很多函数之间的关系,之间参数的传递等等。都是需要考虑的问题。

    记得某位C 大神说过,只有在亲身实践中才能学习到真正的东西。另有古人云:键盘不敲烂,月薪不过万。。。。。

    凡事从小处着手,慢慢的接近大项目,才是正道。好了废话不多说

    先看头文件吧,

    #ifndef MAIN_H
    #define MAIN_H
    
    #include "stdio.h"
    #include "math.h"
    
    int  check_balance(int);
    int  drewmoney(int);
    int  reset_password(int);
    void take_card();
    int  save_money(int );
    
    
    #endif

    主函数:

    #include "main.h"
    
    int main()
    {
        int account_temp,password_temp,slect_temp;
        int account = 123456;//账户  
        int password = 123456;//密码  
        int balance = 1000;//余额  
        printf("welcome to use the ATM !
    
    ");
        while(1)
        {
            printf("please input your account number :");
            scanf("%d",&account_temp);
            printf("please input your password :");
            scanf("%d",&password_temp);
            
            if (account_temp==account&&password_temp==password)
            {
                printf("your account balance is : %d
    
    ",balance);
                break;
            }
            else
            {
                printf("account or password error!!
    ");
                continue;
            }
        }
        
        do
        {    
            printf("**************
    ");
            printf("1.check the balance.
    ");
            printf("2.withdrew money.
    ");
            printf("3.reset password.
    ");
            printf("4.take card.
    ");
            printf("5.save money.
    ");
            printf("**************
    ");
            printf("
    		 please Select the project you want to serve:
    ");
            scanf("%d",&slect_temp);
            
            switch(slect_temp)
            {
                case 1:
                    check_balance(balance);
                    break;
                case 2:
                    balance = drewmoney(balance);
                    break;
                case 3:
                    password = reset_password(password);
                    break;
                case 4:
                    take_card();
                    break;
                case 5:
                    balance = save_money(balance);
                    break;        
            }
        }while(slect_temp!=4);
        return 0;
    }

    小函数的实现:

    #include"main.h"
    
    //查询账户余额  
    int  check_balance(int balance)
    {
        int b;
        b = balance;
        printf("your account balance is :%d $
    
    ",b);
    }
    
    
    //取钱,输入要取金额,金额不足,更新余额。 
    int drewmoney(int balance)
    {
        int drew_account,deviation;
        printf("please input the account you want to  drew :");
        scanf("%d",&drew_account);
        deviation = balance - drew_account;
        if(deviation < 0)
            printf("your account balance is not enough!
    ");
        else printf("please keep your cash: %d $
    ",drew_account);
        
        return deviation;    //返回余额    
    }
    
    //重置密码,返回新密码 
    int reset_password(int password)
    {
        int original,new_pass;
        while(1)
        {
            printf("please input the original password:
    ");
            scanf("%d",&original);
            if(original==password)
                break;
            else 
            {
                printf("input error!!
    ");
                continue;
            }
        }
        
        while(1)
        {
            printf("please input your new password with Six digit number:
    ");
            scanf("%d",&password);
            printf("please input again:
    ");
            scanf("%d",&new_pass);
            if(password == new_pass)
            {
                if(new_pass>100000&&new_pass<999999)
                {
                    printf("reset success!!
    
    ");
                    break;
                }
                else
                {
                    printf("input error!!
    ");
                    continue;
                }
                
            }
            else
            {
                printf("input error --> not same!!
    ");
                continue;
            }
            
        }
        return password;
    }
    
    
    void take_card()
    {
        printf("please take your card!!
    
    ");
    } 
    
    //存钱,返回新的余额 
    int save_money(int balance)
    {
        int save_account;
        printf("please input the save account:
    ");
        scanf("%d",&save_account);
        if(save_account<0)
            printf("sorry,no negative account!!
    ");
        else 
            printf("you have saved money %d $
    ",save_account);
        return balance+save_account;
    }

    运行效果

  • 相关阅读:
    PrintWriter write与println方法的区别
    java线程之一 单线程
    Android系列之ListView实现分页和类似异步加载效果(转载)
    Failed to fetch URL http://dlssl.google.com/android/repository/addons_list
    java rpc 综述(上)
    横竖屏切换时候Activity的生命周期
    【转载】C# 大数相乘
    ASP.NET 2.0 中使用PreviousPage的强类型属性
    人生一世
    SQL 中的indexof函数CHARINDEX
  • 原文地址:https://www.cnblogs.com/qsyll0916/p/7019132.html
Copyright © 2011-2022 走看看