雖然是滿屏的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 !\n\n"); 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\n\n",balance); break; } else { printf("account or password error!!\n"); continue; } } do { printf("**************\n"); printf("1.check the balance.\n"); printf("2.withdrew money.\n"); printf("3.reset password.\n"); printf("4.take card.\n"); printf("5.save money.\n"); printf("**************\n"); printf("\n\t\t please Select the project you want to serve:\n"); 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 $\n\n",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!\n"); else printf("please keep your cash: %d $\n",drew_account); return deviation; //返回余額 } //重置密碼,返回新密碼 int reset_password(int password) { int original,new_pass; while(1) { printf("please input the original password:\n"); scanf("%d",&original); if(original==password) break; else { printf("input error!!\n"); continue; } } while(1) { printf("please input your new password with Six digit number:\n"); scanf("%d",&password); printf("please input again:\n"); scanf("%d",&new_pass); if(password == new_pass) { if(new_pass>100000&&new_pass<999999) { printf("reset success!!\n\n"); break; } else { printf("input error!!\n"); continue; } } else { printf("input error --> not same!!\n"); continue; } } return password; } void take_card() { printf("please take your card!!\n\n"); } //存錢,返回新的余額 int save_money(int balance) { int save_account; printf("please input the save account:\n"); scanf("%d",&save_account); if(save_account<0) printf("sorry,no negative account!!\n"); else printf("you have saved money %d $\n",save_account); return balance+save_account; }
運行效果