c++第3次實驗-定期存款
阿新 • • 發佈:2019-02-04
#include <iostream> using namespace std; int main() { int type; double dMoney,dPeriod,dRate,dInterest; cout<<"歡迎使用利息計算器"<<endl; cout<<"請輸入存款金額:"; cin>>dMoney; cout<<"========存款期限======"<<endl; cout<<"1.3個月"<<endl; cout<<"2.6個月"<<endl; cout<<"3.一年"<<endl; cout<<"4.二年"<<endl; cout<<"5.三年"<<endl; cout<<"6.五年"<<endl; cout<<"請輸入存款期限代號:"; cin>>type; switch(type) { case 1: dPeriod=0.25; dRate=0.031; break; case 2: dPeriod=0.5; dRate=0.033; break; case 3: dPeriod=1; dRate=0.035; break; case 4: dPeriod=2; dRate=0.044; break; case 5: dPeriod=3; dRate=0.05; break; case 6: dPeriod=5; dRate=0.055; break; } dInterest=dMoney*dPeriod*dRate; cout<<"到期利息:"<<dInterest<<"元,本息合計:"<<dInterest+dMoney<<"元"<<endl; cout<<"感謝您的使用,歡迎下次光臨!"<<endl; return 0; }
執行結果: