01.上机目的:学会使用循环控制语句解决实际问题
02.上机内容:编写多分支选择结构程序,根据存款金额,计算利息和本金
03./*
04. * Copyright (c) 2012, 烟台大学计算机学院
05. * All rights reserved.
06. * 作 者:杨绍宁
07. * 完成日期:2012 年 10 月 27 日
08. * 版 本 号:v1.0
09. * 输入描述:存款金额
10.* 程序输出:(要求用switch语句的嵌套完成程序设计)
11.* 问题分析:略
12.* 算法设计:略
*/
#include<iostream>
using namespace std;
int main()
{
double money,rate,period,interest,zhongmoney;
int type,days;
cout << "欢迎使用利息计算器!"<<endl;
cout << "请输入存款金额:";
cin >> money;
cout << "======存款期限======" << endl;
cout << "1. 活期存款" << endl;
cout << "2. 3个月 " << endl;
cout << "3. 6个月" << endl;
cout << "4. 一年 " << endl;
cout << "5. 二年" << endl;
cout << "7. 五年" << endl;
cout << "请输入存款期限的代号:";
cin >> type;
if(type>0 && type<=7)
{
switch(type)
{
period=days/360.0;
case 1:rate=0.005;break;
case 2:rate=0.031;period=0.25;break;
case 3:rate=0.033;period=0.5;break;
case 4:rate=0.035;period=1;break;
case 5:rate=0.044;period=2;break;
case 6:rate=0.050;period=3;break;
case 7:rate=0.055;period=5;break;
}
interest=money*rate*period;
zhongmoney=money+interest;
cout<<"利息"<<interest<<endl;
cout<<"利息+本金"<<zhongmoney<<endl;
}
else
cout<<"选择存款类型错误"<<endl;
return 0;
}
结果:
感受:太有用啦!!!