习题3.13
(1)if语句;
#include <iostream>
using namespace std;
int main() {
int i, m;
cout << "请输入利润(元):";
cin >> i;
cout << "当前利润为" << i << "元,";
//(1)用if语句编程;
if (i <= 100000)m = i * 0.1;
else if (i > 100000 && i <= 200000)m = (i - 100000) * 0.075 + 10000;
else if (i > 200000 && i <= 400000)m = (i - 200000) * 0.030 + 20000;
else if (i > 400000 && i <= 600000)m = (i - 400000) * 0.015 + 40000;
else if (i > 600000 && i <= 1000000)m = (i - 600000) * 0.010 + 60000;
else m = (i - 1000000) * 0.010 + 100000;
cout << "应得奖金总数为:" << m << "元。" << endl;
return 0;
}
(2)switch语句。
#include <iostream>
using namespace std;
int main() {
int i, n;
cout << "请输入利润(元):";
cin >> i;
cout << "当前利润为" << i << "元,";
switch (i / 100000) {
case 0:n = i * 0.1; break;
case 1:n = (i - 100000) * 0.075 + 10000; break;
case 2:
case 3:n = (i - 200000) * 0.030 + 20000; break;
case 4:
case 5:n = (i - 400000) * 0.015 + 40000; break;
case 6:
case 7:
case 8:
case 9:n = (i - 600000) * 0.010 + 60000; break;
default :n = (i - 1000000) * 0.010 + 100000; break;
}
cout << "应得奖金总数为:" << n << "元。" << endl;
return 0;
}