Thread: Class Program: Help with Calculating Account Usage

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    5

    Class Program: Help with Calculating Account Usage

    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.

    Code:
    //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
    Last edited by ThePhenom; 09-28-2007 at 12:56 AM. Reason: Forgot to add code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 6
    Last Post: 04-27-2006, 10:55 AM
  3. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM