Answer:
In C++:
#include <iostream>
using namespace std;
int main(){
int hour; char pkg; float bill = 0;
cout<<"Package: "; cin>>pkg;
cout<<"Hour: "; cin>>hour;
if(hour<=744 && hour >=0){
switch (pkg) {
case 'A':
bill = hour * 9.95;
if(hour >10){bill = 10 * 9.95 + (hour - 10) * 2;}
break;
case 'B':
bill = hour * 14.5;
if(hour >10){bill = 20 * 14.5 + (hour - 20) * 1;}
break;
case 'C':
bill = 19.95;
break;
default:
cout << "Package must be A, B or C";}
cout<<"Total Bills: $"<<bill; }
else{ cout<<"Hour must be 0 - 744"; }
return 0;
}
Explanation:
This declares all variables: int hour; char pkg; float bill=0;
This prompts the user for package type: cout<<"Package: "; cin>>pkg;
This prompts the user for number of hours: cout<<"Hour: "; cin>>hour;
This checks if hour is between 0 and 744 (inclusive)
if(hour<=744 && hour >=0){
If true, the following is executed
A switch statement to check valid input for package
switch (pkg) {
For 'A' package
case 'A':
Calculate the bill
<em> bill = hour * 9.95;</em>
<em> if(hour >10){bill = 10 * 9.95 + (hour - 10) * 2;}</em>
End of A package: break;
For 'B' package
case 'B':
Calculate the bill
<em> bill = hour * 14.5;</em>
<em> if(hour >10){bill = 20 * 14.5 + (hour - 20) * 1;}</em>
End of B package:<em> </em>break;
For C package
case 'C':
Calculate bill: bill = 19.95;
End of C package: break;
If package is not A, or B or C
default:
Prompt the user for valid package cout << "Package must be A, B or C";}
Print total bills: cout<<"Total Bills: $"<<bill; }
If hour is not 0 to 744: <em>else{ cout<<"Hour must be 0 - 744"; }</em>