Question: For C + + A mobile phone service provider has three different data plans for its customers: Plan A - For $ 3 9 .

For C++
A mobile phone service provider has three different data plans for its customers:
Plan A - For $39.99 per month, 2 gigabytes are provided. Additional usage costs $8.00 per gigabyte.
Plan B - For $59.99 per month, 8 gigabytes are provided. Additional usage cost $8.00 per gigabyte.
Plan C - For $79.99 per month, unlimited data is provided.
Write a program that calculates a customer's monthly bill. It should input the customer name, which plan was purchased, and how many gigabytes were used. It should then create a bill that includes the input information and the total amount due. It should also display how much money plan A customers would save if they purchased plan B or C, and how much money plan B customers would save if they purchased plan C. If there would be no savings, no message should be printed. Wherever possible, use named constants instead of numbers, this part is important.
This is what I have and it's not doing the savings correctly. What am I missing?
#include
#include
using namespace std;
// Constants
const double plan_A_price =39.99;
const int plan_A_included =2;
const double plan_A_extra =8.00;
const double plan_B_price =59.99;
const int plan_B_included =8;
const double plan_B_extra =8.00;
const double plan_C_price =79.99;
// To calculate total bill for each plan
void calculateBill(char plan, double usedData){
double totalCost, savingsB, savingsC;
switch (plan){
case 'A':
totalCost = plan_A_price;
if (usedData > plan_A_included){
totalCost +=(usedData - plan_A_included)* plan_A_extra;
}
savingsB =(totalCost < plan_B_price)? plan_B_price - totalCost : 0;
savingsC =(totalCost < plan_C_price)? plan_C_price - totalCost : 0;
break;
case 'B':
totalCost = plan_B_price;
if (usedData > plan_B_included){
totalCost +=(usedData - plan_B_included)* plan_B_extra;
}
savingsB =0;
savingsC =(totalCost < plan_C_price)? plan_C_price - totalCost : 0;
break;
case 'C':
totalCost = plan_C_price;
savingsB =0;
savingsC =0;
break;
default:
cout << "Invalid plan choice." << endl;
return;
}
// To display the bill
cout << fixed << setprecision(2);
cout << "Total Amount Due: $"<< totalCost << endl;
// To display the savings for Plan A and Plan B customers
if (plan =='A'){
if (totalCost < plan_B_price && savingsB >0){
cout << "Savings if you had purchased Plan B: $"<< savingsB << endl;
}
if (totalCost < plan_C_price && savingsC >0){
cout << "Savings if you had purchased Plan C: $"<< savingsC << endl;
}
} else if (plan =='B'){
if (totalCost < plan_C_price && savingsC >0){
cout << "Savings if you had purchased Plan C: $"<< savingsC << endl;
}
}
}
int main(){
string customerName;
char planPurchased;
double gigabytesUsed;
cout << "Enter customer name: ";
cin >> customerName;
cout << "Enter plan purchased (A, B, or C): ";
cin >> planPurchased;
cout << "Enter the number of gigabytes used: ";
cin >> gigabytesUsed;
cout <<"------------------"<< endl;
cout << "Your Phone Bill" << endl;
cout << "Customer Name: "<< customerName << endl;
cout << "Plan Purchased: "<< planPurchased << endl;
cout << "Gigabytes Used: "<< gigabytesUsed << endl;
calculateBill(toupper(planPurchased), gigabytesUsed);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!