If someone could help me out with this, we are supposed to use the switch statem
ID: 3863305 • Letter: I
Question
If someone could help me out with this, we are supposed to use the switch statement.
C++ LANGUAGE
Mobile Service Provider A mobile phone service provider has three different subscription packages for its customers: Package For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute. Package For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute. Package For $69.99 per month unlimited minutes provided. C: Write a program that calculates a customer's monthly b It should ask which package the customer has purchased and how many minutes were used. It should then display the total amount due. Input validation: Be sure the user only selects package A, B, or CExplanation / Answer
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
std::string package;
std::string minsUsed;
double totalBill;
char x[5];
std::cout << "What is your package? ";
getline (std::cin, package);
std::cout << "What is your total minutes used? ";
getline (std::cin, minsUsed);
strcpy(x,package.c_str());
switch(x[0]){
case 'A':
if (atof(minsUsed.c_str()) <= 450 ) {
totalBill = 39.99;
}
else {
totalBill = 39.99 + (atof(minsUsed.c_str()) - 450 ) * 0.45;
}
break;
case 'B':
if (atof(minsUsed.c_str()) <= 900 ) {
totalBill = 59.99;
}
else {
totalBill = 59.99 + (atof(minsUsed.c_str()) - 900 ) * 0.40;
}
break;
case 'C':
totalBill = 69.99;
break;
default:
cout << "Please enter correct package either A/B/C";
return 1;
}
cout << "Total bill is:"<<totalBill<<"$";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.