ex 6 cable cannot call function correctly

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>
using namespace std;

const double RESIDENTIAL_SERVICE_FEE = 40.50;
const double RESIDENTIAL_COST_OF_PREMIUM_CHANNELS = 10.50;
const double BUSINESS_SERVICE_FEE = 75.00;
const double 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();

}
else if(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()
{

switch(askCustomerType())

{

case 'r':
case 'R':

printBill();

break;

case 'b':
case 'B':

printBill();

break;

}

}
int main()
{
welcome();
processBill();

cout << endl;
system("Pause");
return 0;
}
Function printBill is declared like this: void printBill(char ans).

That means it requires one parameter which is of type char.

However, you code attempts to call the function like this: printBill(); i.e. there is no parameter supplied.

You need to change either the function call, or the function definition so they match.
In your function processBill() you call printBill(). but the function takes a char argument as defined.

void printBill(char ans){...}

you'll need to provide a char to printBill(). probably 'r' or 'b'.
hi thank you but when i change my function call printBill(); to printBill(ans); it says its undefined?
Last edited on
Hi ! Use code tags please :D
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
/*
Andrew Do
CS A150
September 23, 2012

Exercise 6
*/

#include <iostream>
using namespace std;

const double RESIDENTIAL_SERVICE_FEE = 40.50;
const double RESIDENTIAL_COST_OF_PREMIUM_CHANNELS = 10.50;
const double BUSINESS_SERVICE_FEE = 75.00;
const double 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();

}
else if(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.
1
2
if(ans == 'r' || ans == 'R')
   ans = 'r';


Last edited on
thank you !
Topic archived. No new replies allowed.