Hi currently need help with editing this code. My professor said my code needs to have if, if-else, and if-else if statements in it. From what it looks like I'm missing if-else-if statements in my code. I need help with editing the code with if-else-if statements including any other "if or if-else" if needed in the code. I provided pictures of the code instructions and how the output and input validation needs to look. here's the code I currently have: #include #include #include 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; } switch (packageType) { // Monthtly Charges for Plan A case 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; } break; } // Monthtly Charges for Plan B case 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; } break; } // Monthly Charges for Plan C case 3: { monthlyCharges = 75; break; } } // Display the monthly total amount cout << "The total amount due is $" << monthlyCharges << endl; cout << endl; return 0; }
Hi currently need help with editing this code. My professor said my code needs to have if, if-else, and if-else if statements in it. From what it looks like I'm missing if-else-if statements in my code. I need help with editing the code with if-else-if statements including any other "if or if-else" if needed in the code. I provided pictures of the code instructions and how the output and input validation needs to look.
here's the code I currently have:
#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;
}
switch (packageType) {
// Monthtly Charges for Plan A
case 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;
}
break;
}
// Monthtly Charges for Plan B
case 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;
}
break;
}
// Monthly Charges for Plan C
case 3: {
monthlyCharges = 75;
break;
}
}
// Display the monthly total amount
cout << "The total amount due is $" << monthlyCharges << endl;
cout << endl;
return 0;
}



Converted the code into if else format from switch case format
Step by step
Solved in 2 steps with 1 images









