943,944 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1958
  • C++ RSS
Sep 28th, 2007
0

Class Program: Help with Calculating Account Usage

Expand Post »
I am hoping someone can help guide me in the right direction.
I have a project for class that I am working on and I could use some help. The project guidelines are below as well as my code thus far.
I have gotten this far with it but am having trouble specifically on accounting for the maximum hours in a month, and in Package B where it talks about charging $1 per 3-hour unit over 50 hours. Currently, my code is charging $1 per hour over 50 hours which is incorrect.
Thanks in advance for any assistance.

DROP LEAP YEAR REQUIREMENT
ASSUME FEB 672 hrs
An Internet service provider has three different subscription packages for its customers:

Package A: For $12 per month with 10 hours of access provided.
Additional hours are $2.00 per hour for the next
20 hours of usage. Then the charges are $1.00 for
each additional hour thereafter.
Assume usage is recorded in one-hour increments,
i.e., a 25-minute session is recorded as one hour.

Package B: For $18 per month with 20 hours of access provided.
Additional hours are $1.00 per hour for the next
30 hours of usage. Then the charges are $1.00 for
each additional 3-hour unit of usage thereafter,
i.e., 1 or 2 hour(s) of aggregated usage would be
charged $1.00.

Package C: For $25 per month with 200 hours access is provided.
Additonal $10 for the next 250 hours and an additional
$15 for usage over 450 hours.

Write a program that calculates a customer’s monthly charges.
Must account for the maximum hours in a month.
Validate all input.

C++ Syntax (Toggle Plain Text)
  1. //Program 2 ISP Packages
  2.  
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. void main()
  10. {
  11. int pkg;
  12. cout<<"Enter pkg: ";
  13. cin>>pkg;
  14.  
  15. if( pkg==1 || pkg==2 || pkg==3)
  16. {
  17. int hrs;
  18. cout<<"Enter hrs: ";
  19. cin>>hrs;
  20.  
  21. if( hrs>= 0 && hrs<=720 )
  22. {
  23. int chg;
  24. switch(pkg)
  25. {
  26.  
  27. case 1:
  28. chg = 12 + ( (hrs>10) ? (hrs-10)*2 : 0 );
  29. break;
  30.  
  31. case 2:
  32. {
  33. chg = 18 + ( (hrs>20 && hrs<=50) ? (hrs-20)*1 : 0 ); //Case 2 is working except for the $1
  34. chg = 18 + ( (hrs>50) ? 30 + (hrs - 50)*1 : (hrs-20)*1); //for each 3-hour unit. I'm charging
  35. break; //$1 per hour. Must fix!
  36. }
  37. case 3:
  38. {
  39. if (hrs<=200)
  40. {
  41. chg=25;
  42. }
  43. else if (hrs>200 && hrs<=450)
  44. {
  45. chg=35;
  46. }
  47. else if (hrs>450)
  48. {
  49. chg=50;
  50. }
  51. break;
  52. }
  53.  
  54. default:
  55. break;
  56. }
  57.  
  58. cout<<"charges: "<<chg<<endl;
  59. }
  60. else
  61. {
  62. cout<<"Invalid hrs"<<endl;
  63. }
  64.  
  65. }
  66. else
  67. {
  68. cout<<"Invalid pkg"<<endl;
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75. }//main
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ThePhenom is offline Offline
4 posts
since Sep 2007
Sep 29th, 2007
0

Re: Class Program: Help with Calculating Account Usage

Anyone have any advice on directing me?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ThePhenom is offline Offline
4 posts
since Sep 2007
Sep 30th, 2007
0

Re: Class Program: Help with Calculating Account Usage

Well, I'm almost done with it for the most part, but still don't know how to compensate for months with 28, 30 or 31 days. It's not 100% complete but it's going in the right direction.
Would anyone mind giving me some feedback on how to compensate for different days per month?
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. void main()
  7. {
  8. int pkg;
  9. cout<<"Enter pkg: ";
  10. cin>>pkg;
  11.  
  12. if( pkg==1 || pkg==2 || pkg==3)
  13. {
  14. int hrs;
  15. cout<<"Enter hrs: ";
  16. cin>>hrs;
  17.  
  18. if(hrs>=0 && hrs<=720)
  19. {
  20. int chg;
  21. switch(pkg)
  22. {
  23. case 1:
  24. chg = 12 + ( (hrs>10) ? (hrs-10)*2 : 0 );
  25. break;
  26.  
  27. case 2:
  28. {
  29. if (hrs<=20)
  30. chg= 18;
  31. else if (hrs>20 && hrs <=50)
  32. chg= 18+( (hrs>20 && hrs<=50) ? (hrs-20)*1 : 0 );
  33.  
  34. else if (hrs>50)
  35. chg= 48+(hrs+2-50)/3;
  36.  
  37. break; }
  38. case 3:
  39. {
  40. if (hrs<=200)
  41. {
  42. chg=25;
  43. }
  44. else if (hrs>200 && hrs<=450)
  45. {
  46. chg=35;
  47. }
  48. else if (hrs>450)
  49. {
  50. chg=50;
  51. }
  52. break;
  53. }
  54.  
  55. default:
  56. break;
  57. }
  58.  
  59. cout<<"charges: "<<chg<<endl;
  60. }
  61. else
  62.  
  63. cout<<"Invalid hrs"<<endl;
  64.  
  65.  
  66. }
  67. else
  68. {
  69. cout<<"Invalid pkg"<<endl;
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76. }//end main
Last edited by ThePhenom; Sep 30th, 2007 at 7:25 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ThePhenom is offline Offline
4 posts
since Sep 2007
Sep 30th, 2007
0

Re: Class Program: Help with Calculating Account Usage

Welcome to DaniWeb!

Congrats on use of code tags when posting code to this board!

The use of void as the return type for main() on code posted here will earn you demerits if done over time. The return type for main() should be int because: it's the standard, even if your compiler allows for the void return type most other compilers won't making your code much less portable, and int is one less keystroke that void anyway.

You should have a three tiered approach to case 1 in the switcht statement, very similar to what you've posted for case 2.

I'd be very surprised if you need to somehow compensate for the different number of days in the month in your program. To do that is possible if you must. To do it I'd start with placing the months with 31 days in one container (probably an array, but a list would do if want, and there are certainly other viable container candidates as well), and months with 30 days in a second container. That only leaves Feb which will have 28 unless it's a leap year, in which case it will have 29. Calculating a leap year is a bit complicated as the formula is something like: it's a leap year if year modulo 4 or year except if year modulo 100 is also zero except if year modulo 400 is zero it is a leap year, though don't quote me on that protocol. Once you've got the two containers set up and a way to deal with Feb, then you'd cycle through the containers to find which one the input month is in if it's not Feb and adjust your pricing accordingly, though there is no formula I see in the instructions posted as to how to adjust for monthly variations regarding days in the month.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Sep 30th, 2007
0

Re: Class Program: Help with Calculating Account Usage

Lerner,
Thanks for the advice. I'll work on it some more and will report back. Thanks a bunch.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ThePhenom is offline Offline
4 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: write and delete details on csv file in C++
Next Thread in C++ Forum Timeline: Getting last value twice from file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC