描述
牛牛商场促销活动:
满100打9折;
满500打8折;
满2000打7折;
满5000打6折
牛阿姨算不清楚自己应该付多少钱,请你帮忙算一下
输入描述:
牛阿姨购买商品打折前的总金额
输出描述:
参加活动后,牛阿姨购买商品应付金额。(保留小数点后1位)
示例1
输入:
654
输出:
523.2
分析:
C++头文件<iomanip>中函数fixed(),解决小数点位数问题。余下部分,用elseif即可。
代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a;
cin >> a;
if(a >= 5000) {
cout << fixed << setprecision(1) << 0.9*a << endl;
} else if (a >= 2000 && a < 5000) {
cout << fixed << setprecision(1) << 0.7*a << endl;
} else if (a >= 500 && a < 2000) {
cout << fixed << setprecision(1) << 0.8*a << endl;
} else if (a >= 100 && a < 500) {
cout << fixed << setprecision(1) << 0.9*a <<endl;
} else if (a > 0 && a < 100) {
cout << fixed << setprecision(1) << a << endl;
} else {
return 0;
}
return 0;
}