-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise8-1.cpp
50 lines (40 loc) · 1.16 KB
/
exercise8-1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*)某货物单价100元,若买100个及以上按九五折优惠,500个及以上按九折计算。输入购买个数,求总款数(结果保留两位有效数字),当输入购买个数为非法(小于0)时,给出提示信息。(选择)*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float price, discount, amount;
int count;
cout << "输入购买件数:" << endl;
cin >> count;
cout << "输入单价:" << endl;
cin >> price;
if (count <= 0)
cout << "输入购买件数非法!" << endl;
else
{
if (count < 100) // count > 0 && count < 100
discount = 1;
else if (count < 500) // count >= 100 && count < 500
discount = 0.95;
else // count >= 500
discount = 0.9;
amount = price * discount * count;
cout << setiosflags(ios::fixed) << setprecision(2) << "总款为:" << amount << endl;
}
// if(count <= 0){
// cout << "非法";
// return 0;
// }
// if(count > 0 && count < 100){
// discount = 1;
// }
// if(count >= 100 && count < 500){
// discount = 0.95;
// }
// if(count >= 500){
// discount = 0.9;
// }
return 0;
}