虽然是满屏的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 = ;//账户
int password = ;//密码
int balance = ;//余额
printf("welcome to use the ATM !\n\n");
while()
{
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 :
check_balance(balance);
break;
case :
balance = drewmoney(balance);
break;
case :
password = reset_password(password);
break;
case :
take_card();
break;
case :
balance = save_money(balance);
break;
}
}while(slect_temp!=);
return ;
}
小函数的实现:
#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 < )
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()
{
printf("please input the original password:\n");
scanf("%d",&original);
if(original==password)
break;
else
{
printf("input error!!\n");
continue;
}
} while()
{
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>&&new_pass<)
{
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<)
printf("sorry,no negative account!!\n");
else
printf("you have saved money %d $\n",save_account);
return balance+save_account;
}
运行效果