-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path13_01_bill.cpp
More file actions
49 lines (30 loc) · 930 Bytes
/
Copy path13_01_bill.cpp
File metadata and controls
49 lines (30 loc) · 930 Bytes
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
#include <iostream>
using namespace std;
// 34 => 34 * 0.5 = 17
// 45 => 45 * 0.5 => 22.5
// 56 => 50 * 0.5 + 6 * 0.75
// 100 => 50 * 0.5 + 50 * 0.75
// 165 => 50 * 0.5 + 100 * 0.75 + 15 * 1.20
// 270 => 50 * 0.5 + 100 * 0.75 + 100 * 1.20 + 20 * 1.5
// 180 => 50 * 0.5 + 100 * 0.75 + 30 * 1.20
// 300 => 50 * 0.5 + 100 * 0.75 + 100 * 1.20 + 50 * 1.5
int main() {
int units;
cin >> units;
double amount = 0;
if(units <= 50){
amount = units * 0.5;
}else if(units <= 150){
//50 + remaining
amount = 50 * 0.5 + (units-50) * 0.75;
}else if(units <= 250){
// 50 + 100 + remaining
amount = 50 * 0.5 + 100 * 0.75 + (units - 150) * 1.2;
}else{
//50 + 100 + 100 + remaining
amount = 50 * 0.5 + 100 * 0.75 + 100 * 1.20 + (units - 250) * 1.50;
}
cout << "Total Amount: " << amount << endl;
double tax = 0.2 * amount; // 20 percent = 20/100 = 0.2
cout << "Total Bill: " << amount + tax << endl;
}