views:

35

answers:

1

Hi

I'm trying to use:

float divAm = (float)theAngle%(float)rads;

but its saying that Invalid operands to binary %

theAngle and rads are both of type float.

Any suggestions please?

Thanks

+6  A: 

Hi Lily,

The modulus operator is a binary integer operator - it cannot be used with floats. You should use fmod() instead:-

float fmod( float numerator, float denominator );

It's defined in math.h. There is also a version using doubles if you need that.

Echelon
is there anything for DIV please?
Lily
What do you mean by DIV? Do you mean integer division?
JeremyP
I'm struggling to understand what you need. A normal division operator '/' will work with floats. If you really want to do integer division, then assign your floats (via a cast) to ints, and use '/'.
Echelon
yes int division where you have 7 / 3 and this returns 2 instead of 2.3333333
Lily