这次添加的东西就有点多了,废话不多说了,上源码。
#include <iostream>
#define PASSWORD "123456"
using namespace std;
void ShowBalance(); //余额查询
void DrawMoney(); //取款
void SaveMoney(); //存款
void CarryOver(); //转账
/*计算利息的函数
dbAm为本金,dbRa为利率,iTe为存期
函数返回为利息*/
double CountAccrual(double dbAm,double dbRa,int iTe);
int main()
{
string strPassword; //记录用户输入的密码
char cInput; //记录用户输入的选项
cout<<"中国银行欢迎您"<<endl;
cout<<"请输入密码:";
cin>>strPassword; //在这用户输入密码
if(strPassword != PASSWORD)
{
cout<<"你这个笨脑瓜!\n";
return 0;
}
cout<<"1.查询\n"
<<"2.取款\n"
<<"3.存款\n"
<<"4.转账\n"
<<"0.退出\n";
cin>>cInput; //在这用户输入选项
switch(cInput)
{
case '1':
ShowBalance();
return 0;
case '2':
DrawMoney();
return 0;
case '3':
SaveMoney();
return 0;
case '4':
CarryOver();
return 0;
case '0':
cout<<"谢谢,欢迎下次再来!\n";
return 0;
default:
cout<<"输入错误,请不要着急!\n";
}
return 0;
}
void ShowBalance()
{
cout<<"您的余额是100000.00元。\n";
}
void DrawMoney()
{
double dbAmount=0; //取款额
double dbAccrual=0; //利息
double dbRate=0; //利率
int iTerm=0; //存期
char cChoose; //选择的存期
cout<<"请输入金额:";
cin>>dbAmount;
cout<<"1.活期\n"
<<"2.3个月\n"
<<"3.6个月\n"
<<"4.一年\n"
<<"5.二年\n"
<<"6.三年\n"
<<"7.五年\n";
cout<<"选择存期:";
cin>>cChoose;
//这里的利率没做转化,到函数里再做转化
if(cChoose=='1')
{
dbRate=0.5;
cout<<"嗯,确实还没到死期";
}
else if(cChoose=='2')
{
dbRate=3.1;
iTerm=3*30;
}
else if(cChoose=='3')
{
dbRate=3.3;
iTerm=6*30;
}
else if(cChoose=='4')
{
dbRate=3.5;
iTerm=360;
}
else if(cChoose=='5')
{
dbRate=4.4;
iTerm=2*360;
}
else if(cChoose=='6')
{
dbRate=5;
iTerm=3*360;
}
else if(cChoose=='7')
{
dbRate=5.5;
iTerm=5*360;
}
else
{
cout<<"输入错误,拜拜!\n";
}
dbAccrual=CountAccrual(dbAmount,dbRate,iTerm);
cout<<"本金:"<<dbAmount<<"利息:"<<dbAccrual<<endl;
}
void SaveMoney()
{
cout<<"请您将纸币放入进钞口!\n";
}
void CarryOver()
{
cout<<"对不起,功能建设中。\n";
}
double CountAccrual(double dbAm,double dbRa,int iTe)
{
//这里将年利率转化为日利率
double dbAc;//利息
dbAc=dbAm*iTe*(dbRa/100/360);
return dbAc;
}