Hello, I am having trouble with the begging of my code it was working previously but will no longer and I have not been able to backtrack and find the problem. What was originally happening when I ran it was that it would ask for what plan but then no matter what I entered it would reply with entry not valid. Now when I try it (couple hours later(worked on some of the code further into project and had a class)) it asks for plan and when I enter a character and hit return it moves down a line and does nothing.
I am using visual studio.
Any help would be very appreciated.
For reference here is the problem I'm trying to solve.
1.Mobile Service Provider
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 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.
2.Mobile Service Provider, Part 2
Modify the Program so that it also displays how much money Package A customers would save if they purchased packages B or C, and how much money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed.
Here is my code
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
//setting everything to 2 decimal places
cout << fixed << setprecision(2);
//declaring variables
char plan, betterplan;
int numMinutes;
string Cmin = "unlimited";
const int Amin = 450, Bmin = 900;
const double AinitialCost = 39.99, BinitialCost = 39.99, CinitialCost = 39.99, AextraPerMin = .45, BextraPerMin = .40;
double cost, save = 0;
int overmin = 0;
//ask user for their plan and have it inputed
cout << "Please enter what plan you have (A, B, or C)." << endl;
cin >> plan;
//This is where im currently haveing trouble--------------------------------------------------------------------------------------------
//check that they entered a valid plan
while (plan != 'A' || plan != 'B' || plan != 'C');
{
cout << "Your entry was invalid. Please enter A, B or C corrisponding to your plan." << endl;
cin >> plan;
}
//ask user for number of minutes used and have them enter it
cout << "Please enter how many minute you used." << endl;
cin >> numMinutes;
//check that they entered valid number of minutes
while (numMinutes < 0)
{
cout << "Your entry was invalid. Please enter the number of minutes you used, it must be zero or greater." << endl;
cin >> numMinutes;
}
//if they have plan A
if (plan == 'A')
{
//check if they used more minutes then they had
if (numMinutes > Amin)
{
overmin = numMinutes - Amin;
cost = (overmin * AextraPerMin) + AinitialCost;
}
else
{
cost = AinitialCost;
}
//output result
cout << "You chose package " << plan << ", which has a base cost of $" << AinitialCost << " and gives you " << Amin << " minutes." << endl;
//check if they should of choosen a higher plan to save money
if (cost >= BinitialCost && cost < CinitialCost)
{
betterplan = 'B';
save = cost - BinitialCost;
}
else if (cost >= CinitialCost)
{
betterplan = 'C';
save = cost - CinitialCost;
}
}
//if they have plan B
else if (plan == 'B')
{
//check if they used more minutes then they had
if (numMinutes > Amin)
{
overmin = numMinutes - Bmin;
cost = (overmin* BextraPerMin) + BinitialCost;
}
else
{
cost = BinitialCost;
}
//output result
cout << "You chose package " << plan << ", which has a base cost of $" << BinitialCost << " and gives you " << Bmin << " minutes." << endl;
//check if they should of choosen a higher plan to save money
if (cost >= CinitialCost)
{
betterplan = 'C';
save = cost - CinitialCost;
}
}
//if they have plan C
else if (plan == 'C')
{
//output result
cout << "You chose package " << plan << ", which has a base cost of $" << CinitialCost << " and gives you " << Cmin << " minutes." << endl;
cost = CinitialCost;
}
//output result cost
cout << "The total cost will be: " << cost << endl;
//output if they could of saved money
if (save > 0)
{
cout << "By purchaseing plan " << betterplan << " you could of saved $" << save << endl;
}
return 0;
}
|