Functions help

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

What i got so far is this but idk how to make it work in the main

#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();
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;
}
idk how to make it work in the main

I'll point one detail of your code for your:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
char getPackage(); // function returns a char
char getHours(); // function returns a char
void showBill( double chg );  // function requires a double argument

int main()
{
  getPackage(); // the return value of function is not stored/used
  getHours(); // the return value of function is not stored/used
  void showBill(); // this is not a function call.
  // It declares a function that takes no arguments and returns nothing
  // showBill() and showBill(double) are different functions

  return 0;
} 

You can clearly call functions with arguments and use their return values.
(Calls to validHours and validPackage.) Calling functions from main() is no different.


PS. Please use the code tags.


Edit: A doublepost. Original here: http://www.cplusplus.com/forum/beginner/187459/
Last edited on
Topic archived. No new replies allowed.