iMobile.cpp iMobile is a mobile phone service company that offers three different data plans to its customers. O Plan A: Price: $39.99 per month. Data allowance: Includes 4 gigabytes of data. Additional data costs $10 per gigabyte. O Plan B: Price: $59.99 per month. Data Allowance: Includes 8 gigabytes of data. Additional data costs $5 per gigabyte. O Plan C: Price: $69.99 per month. Data Allowance: Unlimited
Hi, need help with this code. my professor mentions that we need to use if and switch statements for this code. In not sure if both switch and if statements can be used in the same code. the code below only has if statements. can both switch and if can be used? need help please. I provided pictures of code instructions and how the output/input validation needs to look.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//variables and constants
int packageType;
double dataUsed;
double monthlyCharges = 0.0;
// Name of the program
cout << "iMobile Bill Calculator ..." << endl;
// Display the pacakge options for user to pick
while (true)
{
cout << "\nSelect a subscription :" << endl;
;
cout << "\t\t1. Package A" << endl;
cout << "\t\t2. Package B" << endl;
cout << "\t\t3. Package C" << endl;
cout << "Package: ";
cin >> packageType;
// When a package number is not vaild
if (packageType >= 1 && packageType <= 3)
break;
else
cout << "Error ... Invalid package. Try again." << endl;
}
// When Gigabytes entered is not valid
while (true)
{
cout << "\nHow many gigabytes of data were used? ";
cin >> dataUsed;
if (dataUsed < 0)
{
cout << "Error ... Invalid gigabytes entered. Try again." << endl;
}
else
break;
}
// Monthtly Charges for Plan B
if (packageType == 1)
{
if (dataUsed >= 0 && dataUsed <= 4)
{
monthlyCharges = 39.99;
}
// Monthtly Charges for Plan A with additional data costs
else
{
monthlyCharges = 39.99 + (dataUsed - 4) * 10;
}
}
// Monthtly Charges for Plan B
else if (packageType == 2)
{
if (dataUsed >= 0 && dataUsed <= 8)
{
monthlyCharges = 59.99;
}
// Monthtly Charges for Plan B with additional data costs
else
{
monthlyCharges = 59.99 + (dataUsed - 8) * 5;
}
}
// Monthly Charges for Plan C
else if (packageType == 3)
{
monthlyCharges = 75;
}
// Display the monthly total amount
cout << "The total amount due is $" << monthlyCharges << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images