I've been working on this code for hours trying to find a reason why my switch statement won't run and I've run out of ideas. Anyone see what the issue might be?
The program question I'm trying to solve if needed is: A mobile phone service provider has three different subscription packages for its customers:
Package A: For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute.
Package B: For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute.
Package C: For $69.99 per month unlimited minutes are provided.
Write a program that calculates a customer’s monthly bill. 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 C.
When I run the program, I'm able to select a Package and then it asks to type the minutes used, after that it just says "Press Any Key to Continue"
Thanks for any help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
using namespace std;
int main()
{
int time;
double total = 0.0;
// Store the package and rates in variables.
double packageA = 39.99;
double packageB = 59.99;
double packageC = 69.99;
double rateD = 0.45;
double rateE = 0.40;
char package;
//Display the following choices for the user.
cout << "Select a subscription package. " << endl;
cout << "A. Package A" << endl;
cout << "B. Package B" << endl;
cout << "C. Package C" << endl;
cin >> package;
// Validation
if (package < 'A' || package > 'C')
{
cout << "Package must be A, B, or C. ";
return 1;
}
cout << "How many minutes were used? " << endl;
cin >> time;
switch (package)
{
case 'A':
{
if (time < 450)
total = packageA;
// If the time is less than required. Then no extra charge.
else
total = ((time - 450)*rateD) + packageA;
// If the time exceeds the requirements, then a extra charge is added.
break;
}
case 'B':
{
if (time < 900)
total = packageB;
else
total = ((time - 900)*rateE) + packageB;
break;
}
case 'C':
{
total = packageC;
break;
}
default: cout << "Total amount due is: $" << total << endl;
}
system("pause");
return 0;
}
|