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

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

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.

Lerner,
Thanks for the advice. I'll work on it some more and will report back. Thanks a bunch.

This article has been dead for over six months. Start a new discussion instead.