hi i cannot seem to call the function printBill() correctly for processBill(). I had to use a switch statement to call printBill() but it says too few arguments in function call? im not sure what i did wrong someone please help and thank you.
/*
Andrew Do
CS A150
September 23, 2012
Exercise 6
*/
#include <iostream>
usingnamespace std;
constdouble RESIDENTIAL_SERVICE_FEE = 40.50;
constdouble RESIDENTIAL_COST_OF_PREMIUM_CHANNELS = 10.50;
constdouble BUSINESS_SERVICE_FEE = 75.00;
constdouble BUSINESS_COST_OF_EACH_PREMIUM_CHANNELS = 20.50;
void welcome()
{
cout << " *** Welcome to OCC Cable! ***\n"
<< "\n"
<< "We will help you compute your cable bill.\n";
}
char askCustomerType()
{
char ans;
cout << "\n"
<< "Enter customer type => R, r (Residential), B, b (Business): ";
cin >> ans;
return ans;
}
double residentialBill()
{
return (RESIDENTIAL_SERVICE_FEE + RESIDENTIAL_COST_OF_PREMIUM_CHANNELS);
}
double businessBill()
{
return (BUSINESS_SERVICE_FEE + BUSINESS_COST_OF_EACH_PREMIUM_CHANNELS);
}
void printBill(char ans)
{
if(ans == 'r' || 'R')
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "\n"
<< "Cost for residential customers\n"
<< " Service Fee: $40.50\n"
<< " Premium Channels cost: $10.50\n"
<< " Total bill: " << residentialBill();
}
elseif(ans == 'b' || 'B')
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "\n"
<< "Cost for business customers\n"
<< " Business service fee = $75.00\n"
<< " Business cost of each premium channels = $20.50\n"
<< " Total bill: " << businessBill();
}
}
void processBill()
{
char answer = askCustomerType(); //save the return type
switch(answer)
{
case'r': //should be just 1 case
case'R':
printBill(answer); //takes a char as an argument -
break;
case'b': //should be just 1 case
case'B':
printBill(answer);
break;
}
}
int main()
{
welcome();
processBill();
cout << endl;
system("Pause");
return 0;
}
I gave a quick fix to the problem. There's 2 options here but u want the first one because u only want to ask the user once:
1 2
printBill(answer);
printBill(askCustomerType());
U should really have function prototypes in there too (above main()) and have main() as the first 'function definition' - with the other functions defined below. There's really no good reason to avoid having function prototypes.
Also, instead of askCustomerType() returning a possible of 4 different outcomes which have to be checked later in the switch statement it'll be better to aggregate the outcomes into 2 possibilities and have askCustomerType() return 1 of those 2 possibilities.