-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoreSwitchStatement.cpp
93 lines (75 loc) · 1.7 KB
/
MoreSwitchStatement.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Chapter 04, Programming Challenge 23, This programm will calculate the
// a customer's monthly bill
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Constant
const double PACKAGE_A = 9.95;
const double PACKAGE_B = 14.95;
const double PACKAGE_C = 19.95;
// Variables
char choice;
int hrs;
double extra;
double bill;
//
cout << "Which package does the customer use (A, B, C)?";
cin >> choice;
// Set the numeric output formatting
cout << fixed << showpoint << setprecision(2);
// Calculate and display areas
switch (choice)
{
// Calculate package A charges
case 'A':
cout << "How many hours did the customer use? ";
cin >> hrs;
if (hrs < 1 || hrs > 744)
cout << "Invalid input for the hours!\n";
else if (hrs < 745)
{
if (hrs > 10)
{
extra = (hrs - 10) * 2;
bill = PACKAGE_A + extra;
}
if (hrs <= 10)
bill = PACKAGE_A;
cout << "The charge are: $" << bill << endl;
}
break;
// Calculate the package B charges
case 'B':
cout << "How many hours did the customer use? ";
cin >> hrs;
if (hrs < 1 || hrs > 744)
cout << "Invalid input for the hours!\n";
else if (hrs < 745)
{
if (hrs > 20)
{
extra = (hrs - 20) * 1;
bill = PACKAGE_B + extra;
}
if (hrs <= 20)
bill = PACKAGE_B;
cout << "The charge are: $" << bill << endl;
}
break;
// Calculate package C charges
case 'C':
cout << "How many hours did the customer use? ";
cin >> hrs;
if (hrs < 1 || hrs > 744)
cout << "Invalid input for the hours!\n";
else if (hrs < 745)
bill = PACKAGE_C;
cout << "The charges are: $" << bill << endl;
break;
default:
cout << "Enter A, B or C for the package\n";
}
return 0;
}