Jump to content

Need help with a programming problem

Go to solution Solved by madknight3,

This

int package;

Should be

char package;

Hi im new to c++ cant figure out what im doing wrong when im writting this program. it keps automatically going to default and quitting when i input an answer. am i doing something wrong with the switch statement or the if statement?

 

Exercise #3 – ISP Problem
An Internet service provider has three different subscription packages for its customers.
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 in a month
cannot exceed 744.

 

 

what i have so far

 

#include <iostream>

using namespace std;

int main()
{
    int package;
    double hours, due;
    cout << "How many hours were you on the internet this month? ";
    cin >> hours;

    cout << "Enter your Package A, B or C: ";
    cin >> package;
    if (hours > 0 && hours < 744)
    {
        switch (package)
        {
        case 'a':
        case 'A':
            if (hours > 10)
            {
                due = (hours - 10) * 2 + 9.95;
                cout << "Total for the month: $" << due << endl;
            }
            else if (hours < 10)
            {
                cout << "Total for the month: $9.95";
            }
            break;
        case 'b':
        case 'B':
            if (hours >= 20)
            {
                due = (hours - 20) + 14.95;
                cout << "Total for the month: $" << due << endl;
            }
            else if (hours < 20)
            {
                cout << "Total for the month: $ 14.95";
            }
            break;
        case 'c':
        case 'C':
            due = 19.95;
            cout << "Total for the month: $" << endl;
            break;
    
        }
    }
    else if (hours < 0 || hours > 744)
    {
        cout << "ERROR: please enter a valid number";
    }
    int stop;
    cin >> stop;
}

 

Link to comment
https://linustechtips.com/topic/313594-need-help-with-a-programming-problem/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×