can anyone doublecheck

Hi all can anyone help me if I did this program right.
I am a newbie at this.

An ISP has 3 different subscription packages
a) $19.95 per month, 11 hours access. Additional hours
are $2.00
b) $24.95 per month, 22 hours access. Additional hours
are $1.00
c) $29.95 per month unlimited access
Write a program that calculates a customers monthly bill. Ask which
package how many hours then display the monthly charge.

C++ Code

#include <iostream>
using namespace std;

int main ()
{
int choice;
int hours;
double total;

double A = 19.95;
double B = 24.95;
double C = 29.95;
double D = 2.00;
double E = 1.00;

//Display
cout << " \t\tThe Internet Service Provider Subscription\n";
cout << "1. A.$19.95 per month. 11 hours access. Additional Hours are $2.00\n";
cout << "2. B.$24.95 per month. 22 hours access. Additional hours are $1.00\n";
cout << "3. C.$29.95 per month. Unlimited access.\n";
cout << "Enter your choice: ";
cin >> choice;

if (choice >=1 && choice <=3)
{
cout << "How many hours would you access: ";
cin >> hours;



switch (choice)
{
case 1:
{
total = A + (hours - 11)*2;
break;
}
case 2:
{
total = B + (hours - 22)*1;
break;
}

case 3:
{
total = C;
break;
}

default:
cout<<"You enter a wrong value!"<<endl;
cout << "The valid choices are 1 through 3. \n Run the program again.";

}

cout << "The total charges is equal to:$ "<<total<<endl;
}



else if (choice !=3)

{
cout << "The valid choices are 1 through 3. \n Run the program again.";
}
return 0;
}
Looks good.

On lines 35 and 40 you should have
total = A + (hours - 11)*D;
and
total = B + (hours - 22)*E;
instead of hard-coding '2' and '1'.
Last edited on
Topic archived. No new replies allowed.