Program with Functions

Can anyone help me out?
An Internet service provider has three different subscription packages for its customers:

Package A: For $15 per month with 50 hours of access provided.
Additional hours are $2.00 per hour over 50 hours.
Assume usage is recorded in one-hour increments,


Package B: For $20 per month with 100 hours of access provided.
Additional hours are $1.50 per hour over 100 hours.


Package C: For $25 per month with 150 hours access is provided.
Additional hours are $1.00 per hour over 150 hours

Write a program that calculates a customer’s monthly charges.
Implement with the following functions for your solution.
getPackage
validPackage
getHours
validHours
calculatePkg_A
calculatePkg_B
calculatePkg_C
calculateCharges
showBill

Demonstrate test cases as described in table:

Test Case Package Hours
1 A 50
2 a 51
3 B 100
4 b 101
5 C 149
6 c 251
7 e 720
8 c 722
What exactly do you need help with? What have you code so far?
This is what i have so far




#include <iostream>
using namespace std;

bool validPackage(char x);
char getPackage();
bool validHours(int h);
char getHours();
double calculatePkg_A(int hrs);
double calculatePkg_B(int hrs);
double calculatePkg_C(int hrs);
double calculateCharges(char x, int hrs);
void showBill(double chg);

int main()
{
getPackage();
getHours();
calculateCharges();
void showBill();


return 0;
}
bool validPackage(char x)
{
return (x >= 'A' && x <= 'C') || (x >= 'a' && x <= 'c');
}

char getPackage(){
char x = 0;
do {
cout << "Enter Package: ";
cin >> x;
} while (!validPackage(x));
return x;
}

bool validHours(int h){
return (h >= 0);
}

char getHours(){
int h;
do{
cout << "Enter Hours: ";
cin >> h;
} while (!validHours(h));

return h;
}

double calculatePkg_A(int hrs){
int basecost = 15;
int basehrs = 50;
double extraCost = 2.00;
double cost = hrs > basehrs ? basecost + (hrs - basehrs) * extraCost : basecost;
return cost;
}

double calculatePkg_B(int hrs){
int basecost = 20;
int basehrs = 100;
double extraCost = 1.50;
double cost = hrs > basehrs ? basecost + (hrs - basehrs) * extraCost : basecost;
return cost;
}

double calculatePkg_C(int hrs){
int basecost = 25;
int basehrs = 150;
double extraCost = 1.00;
double cost = hrs > basehrs ? basecost + (hrs - basehrs) * extraCost : basecost;
return cost;
}

double calculateCharges(char x, int hrs){
double chg;
switch (x){
case 'A':
case 'a': chg = calculatePkg_A(hrs);
break;
case 'B':
case 'b': chg = calculatePkg_B(hrs);
break;
case 'C':
case 'c': chg = calculatePkg_C(hrs);
break;
}
return chg;
}

void showBill(double chg)
{
cout << "The amount of money you owe is: " << chg << endl;
}
Line 16: you call getPackage(), but you ignore the result.

Line 17: You call getHours(), but ignore the result.

Line 18: You call calculateCharges(), but pass no arguments. calculateCharges requires two arguments. You ignore the result here also.

Line 19: This is a function prototype, not a function call. Get rid of the void. ShowBill() requires one argument, but you don't pass any.

Line 42: Why is getHours() a char function, while h is an int?

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.




Last edited on
Topic archived. No new replies allowed.