User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,506 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,649 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 929 | Replies: 4
Reply
Join Date: Sep 2007
Posts: 4
Reputation: ThePhenom is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ThePhenom ThePhenom is offline Offline
Newbie Poster

Class Program: Help with Calculating Account Usage

  #1  
Sep 28th, 2007
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.

//Program 2 ISP Packages


#include <iostream>
using namespace std;



void main()
{
    int pkg;
    cout<<"Enter pkg: ";
    cin>>pkg;

    if( pkg==1 || pkg==2 || pkg==3)
    {
        int hrs;
        cout<<"Enter hrs: ";
        cin>>hrs;

        if( hrs>= 0 && hrs<=720 )
        {
            int chg;
            switch(pkg)
            {
            
                case 1:
                    chg = 12 + ( (hrs>10) ? (hrs-10)*2 : 0 );
                    break;

                case 2:
		{
                	chg = 18 + ( (hrs>20 && hrs<=50) ? (hrs-20)*1 : 0 );		//Case 2 is working except for the $1
			chg = 18 + ( (hrs>50) ? 30 + (hrs - 50)*1 : (hrs-20)*1);	//for each 3-hour unit. I'm charging 
                	break;								//$1 per hour. Must fix!
		}
		case 3:
		{
			if (hrs<=200)
			{
				chg=25;
			}
			else if (hrs>200 && hrs<=450)
			{
				chg=35;
			}
			else if (hrs>450)
			{
				chg=50;
			}
			break;
		}

                default: 
                    break; 
            }

            cout<<"charges: "<<chg<<endl;
        }
        else
        {
            cout<<"Invalid hrs"<<endl;
        }

    }
    else
    {
        cout<<"Invalid pkg"<<endl;
    }





}//main
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: ThePhenom is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ThePhenom ThePhenom is offline Offline
Newbie Poster

Re: Class Program: Help with Calculating Account Usage

  #2  
Sep 29th, 2007
Anyone have any advice on directing me?
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: ThePhenom is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ThePhenom ThePhenom is offline Offline
Newbie Poster

Re: Class Program: Help with Calculating Account Usage

  #3  
Sep 30th, 2007
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?
#include <iostream>
using namespace std;



void main()
{
    int pkg;
    cout<<"Enter pkg: ";
    cin>>pkg;

    if( pkg==1 || pkg==2 || pkg==3)
    {
        int hrs;
        cout<<"Enter hrs: ";
        cin>>hrs;

        if(hrs>=0 && hrs<=720)
        {
            int chg;
            switch(pkg)
            {
	case 1:
	     chg = 12 + ( (hrs>10) ? (hrs-10)*2 : 0 );
                    break;

                case 2:
	     {
		if (hrs<=20)
		     chg= 18;
		else if (hrs>20 && hrs <=50)
		     chg= 18+( (hrs>20 && hrs<=50) ? (hrs-20)*1 : 0 );
				
		else if (hrs>50)
		     chg= 48+(hrs+2-50)/3;
					
                                break;							    }
	case 3:
                      {
	       if (hrs<=200)
		{
		chg=25;
		}
	       else if (hrs>200 && hrs<=450)
		{
		chg=35;
		}
	       else if (hrs>450)
		{
		chg=50;
		}
	       break;
	       }

                default: 
                    break; 
            }

            cout<<"charges: "<<chg<<endl;
        }
        else
        
            cout<<"Invalid hrs"<<endl;
        

    }
    else
    {
        cout<<"Invalid pkg"<<endl;
    }





}//end main
Last edited by ThePhenom : Sep 30th, 2007 at 7:25 pm.
Reply With Quote  
Join Date: Jul 2005
Posts: 1,288
Reputation: Lerner is just really nice Lerner is just really nice Lerner is just really nice Lerner is just really nice 
Rep Power: 9
Solved Threads: 175
Lerner Lerner is offline Offline
Nearly a Posting Virtuoso

Re: Class Program: Help with Calculating Account Usage

  #4  
Sep 30th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: ThePhenom is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ThePhenom ThePhenom is offline Offline
Newbie Poster

Re: Class Program: Help with Calculating Account Usage

  #5  
Sep 30th, 2007
Lerner,
Thanks for the advice. I'll work on it some more and will report back. Thanks a bunch.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC