# invalid operands to binary?

This is a discussion on invalid operands to binary? within the C Programming forums, part of the General Programming Boards category; The following lines of code from a function of mine is producing the output (this is just for a couple ...

1. ## invalid operands to binary?

The following lines of code from a function of mine is producing the output (this is just for a couple of the error lines but its all like this):

hours_3b.c:151: error: invalid operands to binary + (have ‘float *’ and ‘float’)
hours_3b.c:153: error: invalid operands to binary + (have ‘float *’ and ‘double’)

Here is the code for the function:

Code:
```if (employeeData[i].hours > STD_HOURS) {
total_grossOT += employeeData[i].gross;
/*Calculates sum total of gross pay */
total_OT += (employeeData[i].hours - STD_HOURS);
/*Calculates sum total of OT */
total_hours += (employeeData[i].hours + employeeData[i].OT);
/*Calculates sum total of hours */
}

else {
employeeData[i].OT = 0;

total_gross += (employeeData[i].wage_rate * employeeData[i].hours);
/*Calculates the sum total of gross pay */
total_hours += employeeData[i].hours;
/*Calculates sum total of hours */
}```
Im trying to figure out why this is happening. All of the variables being used are of type float.

2. Actually, let me put that a different way. Double check the type of thing that you are adding.

c = a + b;
For the best results, c, a and b should all be the same type.

And that type needs to match exactly the type in the binary + operator declaration:
Code:
`type& operator + (const type& a, const type& b);`
You're going to have confusing problems if type is different in places. (Like using pointers)

3. > All of the variables being used are of type float.
Your error messages beg to differ.

> hours_3b.c:151: error: invalid operands to binary + (have ‘float *’ and ‘float’)
> hours_3b.c:153: error: invalid operands to binary + (have ‘float *’ and ‘double’)
Something in each one of them is a pointer.

Did you forget a subscript.

4. What are the types of total_grossOT, total_OT, total_hours, etc.? As was mentioned by your compiler, the one on the left-hand side is a float *, not a float. Try changing the offending line to include a pointer dereference. For example, assuming line 151 has the total_grossOT line, then you can change it to

*total_grossOT += some_float_arg;

That kind of fix should at least remove the compiler error, but it may still have the wrong logic. Pointers must be pointing to some valid memory for that type before you dereference it. If you're just now discovering it's a pointer, you might have forgotten to do this.