Double Variable Evaluating to True

Hi! I am working on the following for an assignment, but I keep returning the same error "Line 33: the address of 'double billingAmount(int, int, int)' will always evaluate as 'true' [-Waddress]". I would love a hand in figuring out how to fix this error. Thanks!

Here is my goal: During the tax season, every Friday, the J&J accounting firm provides assistance to people who prepare their own tax returns. Their charges are as follows:

If a person has low income (<= 25,000) and the consulting time is less than or equal to 30 minutes, there are no charges; otherwise, the service charges are 40% of the regular hourly rate for the time over 30 minutes.
For others, if the consulting time is less than or equal to 20 minutes, there are no service charges; otherwise, service charges are 70% of the regular hourly rate for the time over 20 minutes.
(For example, suppose that a person has low income and spent 1 hour and 15 minutes, and the hourly rate is $70.00. Then the billing amount is 70.00 * 0.40 * (45 / 60) = $21.00.)

Write a program that prompts the user to enter the hourly rate, the total consulting time, and whether the person has low income. The program should output the billing amount. Your program must contain a function that takes as input the hourly rate, the total consulting time, and a value indicating whether the person has low income. The function should return the billing amount. Your program may prompt the user to enter the consulting time in minutes.



Here is my code:

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
#include <iostream>
#include <iomanip>

using namespace std;

// declare billingAmount function
double billingAmount(double hRate, int yearlyIncome, int consTime);

int main()
{
    double hRate;
    int consTime;
    int yearlyIncome;

    cout << fixed << showpoint << setprecision(2);

    cout << "Enter yearly income: ";
    cin >> yearlyIncome;
    cout << endl;

    // set lowIncome
   
    cout << "Enter the hourly rate: ";
    cin >> hRate;
    cout << endl;

    cout << "Enter consulting time in minutes: ";
    cin >> consTime;
    cout << endl;

    // call billingAmount
    cout << "The total billing amount is: $";
    cout << billingAmount;
    cout << "."
         << endl;
  return 0;
}

double billingAmount(double hRate, int yearlyIncome, int consTime)
{
  // write your billingAmount function here
  if (yearlyIncome<=25000) {
      if (consTime<=30)
          return 0;
      else
          return hRate*0.40*((consTime-30)/60);
  }
    else {
        if (consTime<=20)
            return 0;
        else
            return hRate*0.70*((consTime-20)/60);
    }
          
  }
    
Last edited on
billingAmount() is a function with three arguments (see line 39).

You are referring to it on line 33 as a variable with no arguments at all.
Corrected now!

As @lastchance said above, you should have called the billingAmount function with the appropriate arguments.

Likewise, I corrected your calculation of the billing amount, since you were trying to divide an int by an int - which will return an int even for a non-exact division - i have typecasted the numerator to a double, and taken advantage of C++ implicit conversion to evaluate the division to a double type.

Going forward, I will suggest you ask for input time in hour(s), then convert to minute within the code.

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
#include <iostream>
#include <iomanip>

using namespace std;

// declare billingAmount function
double billingAmount(double hRate, int yearlyIncome, int consTime);

int main()
{
    double hRate;
    int consTime;
    int yearlyIncome;

    cout << fixed << showpoint << setprecision(2);

    cout << "Enter yearly income: ";
    cin >> yearlyIncome;
    cout << endl;

    // set lowIncome
   
    cout << "Enter the hourly rate: ";
    cin >> hRate;
    cout << endl;

    cout << "Enter consulting time in minutes: ";
    cin >> consTime;
    cout << endl;

    // call billingAmount
    cout << "The total billing amount is: $";
    cout << billingAmount(hRate, yearlyIncome, consTime);
    cout << "."
         << endl;
  return 0;
}

double billingAmount(double hRate, int yearlyIncome, int consTime)
{
  // write your billingAmount function here
  if (yearlyIncome<=25000) {
      if (consTime<=30)
          return 0;
      else
          return hRate * ((double)(consTime - 30)/60) * 0.4;
  }
    else {
        if (consTime<=20)
            return 0;
        else
             return hRate * ((double)(consTime - 20)/60) * 0.7;
    }
          
  }
    


Test

Enter yearly income: 12000

Enter the hourly rate: 70

Enter consulting time in minutes: 75

The total billing amount is: $21.00
Last edited on
@Kloppite and @lastchance thank you! I did not realize that the way in which I was calling billingAmount was incorrect. As such, I didn't take into account that dividing an int by an int would result in an int, and not a double.

Again, thanks for the help!
Topic archived. No new replies allowed.