Haveing trouble with getting a function to call.
I'm having difficulty with my showBill function and am liking for a little insight.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <iostream>
using namespace std;
void showBill(double chg);
double calculatePkg_A(int hour);
double calculatePkg_B(int hour);
char getValidPkg();
int getValidHrs();
double calculatePkg_C(int hour);
double calculateCharges(char pkg, int hour);
int main()
{
getValidPkg();
cout << "\n";
getValidHrs();
showBill;
return 0;
}
bool isValidPkg( char pkg )
{
return (pkg>='A' && pkg<='C') || (pkg>='a' && pkg<='c');
}
char getValidPkg()
{
char pkg=0;
do
{
cout<<"Enter pkg: ";
cin>>pkg;
}
while( !isValidPkg(pkg) );
return pkg;
}
bool isValidHrs( int hour )
{
return (hour>=0 && hour<=720);
}
int getValidHrs()
{
int hour;
do
{
cout<<"Enter hours: ";
cin>>hour;
}
while( !isValidHrs(hour) );
return hour;
}
double calculatePkg_A(int hour)
{
int baseCost = 15;
int baseHrs = 50;
double extraCost = 2.0;
double cost = hour > baseHrs ? baseCost + ( hour -
baseCost ) * extraCost : baseCost ;
return cost;
}
double calculatePkg_B(int hour)
{
int baseCost = 20;
int baseHrs = 100;
double extraCost = 1.50;
double cost = hour > baseHrs ? baseCost + ( hour -
baseCost ) * extraCost : baseCost ;
return cost;
}
double calculatePkg_C(int hour)
{
int baseCost = 25;
int baseHrs = 150;
double extraCost = 1.00;
double cost = hour > baseHrs ? baseCost + ( hour -
baseCost ) * extraCost : baseCost ;
return cost;
}
double calculateCharges(char pkg, int hour)
{
double chg;
switch(pkg)
{
case 'A':
case 'a': chg = calculatePkg_A(hour);
break;
case 'B':
case 'b': chg = calculatePkg_B(hour);
break;
default: chg = calculatePkg_C(hour);
}
return chg;
}
void showBill(double chg)
{
cout << "Your total is: "
<< chg << endl;
}
|
Your function wants a value, but your not sending it one.
showBill;
should be
showBill (somevalue);
How do I get it to display the functions body. Ex "Your total is: "<< chg<<<endl; from showBills body?
What do you mean by display the function's body? The code will be run when you call the function.
It should work like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
using namespace std;
double chg=0;
int main()
{
chg = 1200;
cout << chg << endl;
showBill (chg);
return 0;
}
void showBill(double chg)
{
cout << "Your total is: "
<< chg << endl;
}
|
Topic archived. No new replies allowed.