In: Computer Science
Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows:
Regular service: $10.00 plus the first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute.
Premium Service: $25.00 plus
in C++ (Basic)
Your program should output the type of service, number of minutes the telephone service was used, and the amount due from the user.
For the premium service, the customer may be using the service during the day and night. Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes the service used during the night.
C++ program :
#include <iostream>
using namespace std;
int main()
{
int choice , minutes, day , night;
double amount;
// Menu for the user
cout << "Welcome to our cellular telephone company!\n";
cout << "We have two services to offer\n";
cout <<"1. Regular Service\n";
cout <<"2. Premium Service\n";
cout << "Please, choose either 1 or 2: ";
cin >> choice;
if(choice == 1) // if user selected 1 as choice then it is regular service
{
cout << "Enter the number of minutes service used : ";
cin >> minutes;
if(minutes <= 50) // calculate amount based on minutes offered
{
amount = 10.00;
}
else // calculate amount based on minutes offered
{
amount = 10.00 + (minutes-50)*0.20;
}
cout <<"\n\nYour Bill\n";
cout <<"---------\n";
cout << "Type of service : Regular\n";
cout << "Number of minutes used : "<<minutes<<"\n";
cout << "Amount due is : $"<<amount<<"\n";
}
else if(choice == 2)
{
cout << "Enter the number of minutes service used during day time: ";
cin >> day;
cout << "Enter the number of minutes service used during night time: ";
cin >> night;
amount = 25.00;
if(day > 75) // calculate amount based on minutes offered for day time
{
amount = amount + (day-75)*0.10;
}
if(night > 100) // calculate amount based on minutes offered for night time
{
amount = amount + (night-100)*0.05;
}
cout <<"\n\nYour Bill\n";
cout <<"---------\n";
cout << "Type of service : Premium\n";
cout << "Number of minutes used : "<<(day+night)<<"\n";
cout << "Amount due is : $"<<amount<<"\n";
}
else
{
cout << "\nInvalid choice!\n";
}
return 0;
}
Outputs and Screenshots :