题解 | #计算商品打折结算金额#
计算商品打折结算金额
https://www.nowcoder.com/practice/055a92b5c93f497291a58c232f59fae9
#include <iostream> #include <iomanip> using namespace std; int main() { double price; cin >> price; double cost = 0.0; // 商品打折,条件语句,分类讨论 if(price < 100) cost = price; if(100 <= price && price < 500) cost = price*0.9; if(500 <= price && price < 2000) cost = price*0.8; if(2000 <= price && price < 5000) cost = price*0.7; if(5000 <= price) cost = price*0.6; cout << setiosflags(ios::fixed) << setprecision(1) << cost << endl; //防止小数点后只有一位且为0时显示为e浮点数,setprecision(n)有n位小数 return 0; }#零基础学习C++#
C++每日一练 文章被收录于专栏
C++刷题