-
Notifications
You must be signed in to change notification settings - Fork 0
/
nestedIfstatements.cpp
48 lines (36 loc) · 1.17 KB
/
nestedIfstatements.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
// Chapter 04, Programming Challenge 10, this program will calculate the cost of the purchase
// from the number of units sold in a software sales company
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Constant
const float PRICE = 99.0;
// Declare variables
int units;
float total;
float discountedPrice;
// Get the number of units sold
cout << "Enter the number of units sold: ";
cin >> units;
// Determine the quantity discount
if (units < 0 || units == 0)
cout << "Invalid number of units" << endl;
else
{if (units < 10 && units > 0)
discountedPrice = PRICE * 1;
else if (units > 9 && units < 20)
discountedPrice = PRICE - (PRICE * 0.2); // 20 % discount
else if (units > 19 && units < 50)
discountedPrice = PRICE - (PRICE * 0.3); // 30 % discount
else if (units > 49 && units < 100)
discountedPrice = PRICE - (PRICE * 0.4); // 40 % discount
else if (units > 99)
discountedPrice = PRICE - (PRICE * 0.5); // 50 % discount
// Calculate and Display the toatl price
total = units * discountedPrice;
cout << "The total cost of the purchase is $" << fixed << showpoint << setprecision(2) << total << endl;
}
return 0;
}