im not really quite sure, if im doing the problem correctly.. this is what i have so far... i need help please

this is the question to the problem im working on.

Package A: For \$9.95 per month 10 hours of access are provided. Additional hours
are \$2.00 per hour.
Package B: For \$14.95 per month 20 hours of access are provided. Additional
hours are \$1.00 per hour.
Package C: For \$19.95 per month unlimited access is provided.
Write a program that calculates a customer s monthly bill. It should ask which package
the customer has purchased and how many hours were used. It should then display
the total amount due.
Input Validation: Be sure the user only selects package A, B, or C. Also, the number
of hours used in a month cannot exceed 744.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````int Package_A = 1, Package_B = 2, Package_C = 3, choice; float const CostA = 9.95, CostB = 14.95, CostC = 19.95; float hours = 0, cost = 0, FeeA = 2, FeeB = 1; cout << "\t Which service would you like ?\n"; << " 1. Package A: 10 hours of access"; << " 2. Package B: 20 hours of access"; << " 3. Package C: unlimited access"; cin >> choice; cout << fixed << showpoint << setprecision (2)<< endl; switch ( choice) { case Package_A: if ( hours > 10) { cost+=CostA + FeeA; cout << " there is an additional fee for exceeding 10 hours\n"; cout << "your total is : "<< cost << endl; } else { cost+=CostA; cout << "the cost for package A is: "<< CostA << endl; } break; } { case Package_B: if ( hours > 20) { cost+=CostB + FeeB; cout << " there is an additional fee for exceeding 10 hours\n"; cout << "your total is : "<< cost << endl; } else { cost+=CostB; cout << "the cost for package A is: "<< CostA << endl; } } ``````
You posted this question before. Go to your account look at your previous posts to see if anyone helped you with your last problem.
obviously i know that. nobody has helped me out, thats why i posted this up again.
I figured you did but didn't wanna be a dick on how you would fail to pin point any specific issues with your code......TWICE.Go check your last question, someone DID help you, and if his input didn't solve your problem be competent enough to state the problem instead of having people hold your hand through this easy assignment.
lol wow. you obviously have nothing better to do than to criticize others for not knowing how to solve an "easy assignment". it may be easy for you but if you know how to READ, it clearly states this forum is for BEGINNERS. now that you feel better about yourself, please do me a favor and go "help" someone else.
closed account (iAk3T05o)
I don't know half of what's in your code but i don't if that's how you wrote it in your ide because i'm sure every program has using namespace std;, int main()( i only know int), #include <iostream> if you want user input and display output etc.
Oh, also watch the way you talk, you need the help, not them.
I don't think it's a good idea to have if statements inside a switch... something like:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768`` ``````#include float getHours(void) { float hours = 0; cout << "How many hours did the user use?" << endl; cin.ignore(); cin >> hours; if(hours > 744) { cout << "Input error!" << endl; exit(1); }else{ return hours; } } void planA(void) { float hours = getHours(); cout << "Cost is : \$" << (Hours*9.95) << endl; } void planB(void) { float hours = getHours(); cout << "Cost is : \$" << (Hours*14.95) << endl; } void planC(void) { float hours = getHours(); cout << "Cost is : \$" << (Hours*19.95) << endl; } void main (int argc, char* argv[]) { char package = ''; cout << "Which plan is the user on (A, B or C)" << endl; cin.ignore(); cin >> package; switch(package) { case 'a': planA(); break; case 'A': planA(); break; case 'b': planB(); break; case 'B': planB(); break; case 'c': planC(); break; case 'C': planC(); break; default: return 1; } return 0; }``````

This code is off the cuff so it might need some debugging... hope it helps though.

Dax.
Last edited on
Its better to have a major function that calculates the bill given the package and hours as argument. It simplifies the program and there isn't a need of a switch statement with if/else statements in it. And I believe my formulas are correct.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859`` ``````#include #include using namespace std; float calc_bill(string package, float hours); int main() { string pack; float hrs; float amt_due; cout << "Select your package: " << endl; cout << "1. Package A\n2. Package B\n3. Package C" << endl; cout << "Pack [a/b/c]: "; cin >> pack; if(!(pack == "A" || pack == "a" || pack == "B" || pack == "b" || pack == "C" || pack == "c")) { cout << "INVALID PACKAGE!" << endl; return 1; } cout << "Enter hours used: "; cin >> hrs; if(hrs > 744) { cout << "Access hours can't exceed 744!" << endl; return 1; } amt_due = calc_bill(pack, hrs); cout << "Total amount due: \$" << amt_due << endl; return 0; } float calc_bill(string package, float hours) { float bill = 0; if(package == "a" || package == "A") { if(hours > 10) { bill = 9.95+(2.00*(hours-10)); } else{bill = 9.95;} } else if(package == "b" || package == "B") { if(hours > 20) { bill = 14.95+(1.00*(hours-20)); } else{bill = 14.95;} } else { bill = 19.95; } return bill; }``````
Topic archived. No new replies allowed.