93.3k views
15 votes
Here is the problem specification: An Internet service provider has three different subscription packages for its customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour. Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour. Package C: For $19.95 per month unlimited access is provided. Write a program that calculates a customer's monthly bill. It should ask which package the customer has purchased and how many hours were used. It should then display the total amount due. Input Validation: Be sure the user only selects package A, B or C. Also, the number of hours used in a month cannot exceed 744. Use switch.

1 Answer

9 votes

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;

}

Step-by-step 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

bill = hour * 9.95;

if(hour >10){bill = 10 * 9.95 + (hour - 10) * 2;}

End of A package: break;

For 'B' package

case 'B':

Calculate the bill

bill = hour * 14.5;

if(hour >10){bill = 20 * 14.5 + (hour - 20) * 1;}

End of B package: 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: else{ cout<<"Hour must be 0 - 744"; }

User William Greenly
by
4.8k points