求知。。。请问这道题if语句的格式是怎么样,switch又怎么用????

来源:百度知道 编辑:UC知道 时间:2024/04/28 00:32:30
企业发放的奖金制度根据利润提成。
利润profit低于或等于10万元时,奖金可提10%;
利润高于10万元,低于20万元时,低于10万元部分可提10%,高于10万部分可提7.5%;
20万<profit<=40万时,高于20万的提5%;
40万<profit<=60万时,高于40万的提3%;
60万<profit<=100万时,高于60万的提1.5%;
profit>100万时,高于100万的提1%。从键盘输入利润,分别使用if语句和switch语句实现输出奖金总数

//设置一个整形变量标志一下输入的profit属于的范围
//整个c++的控制台文件是这样的
#include <iostream>
using namespace std;
int main(){
int profit,flag;
double earnmoney=0;
cout<<"请输入参数利润(单位:万元)"<<endl;
cout<<"字母键退出"<<endl;
int temp=0;
while(cin>>profit){
temp=profit;flag=10;earnmoney=0;
while(flag!=0){
if(profit==0){flag=0;}
else if(profit<=10){flag=1;}
else if(profit>10&&profit<=20){flag=2;}
else if(profit>20&&profit<=40){flag=3;}
else if(profit>40&&profit<=60){flag=4;}
else if(profit>60&&profit<=100){flag=5;}
else if(profit>100){flag=6;}
switch (flag){
case 0:break;
case 6:
earnmoney+=(profit-100)*0.01;
profit=100;
break;
case 5:
earnmoney+=(profit-60)*0.015;
profit=60;
break;
case 4:
earnmoney+=(profit-40)*0.03;
profit=40;
break;