# Thread: error: invalid operands to binary %

1. ## error: invalid operands to binary %

Hi i'm getting this error when i compile this code:

Code:
```#include <math.h>
#include <stdio.h>

int main(void)
{
float num;
int total;

num = pow(2,1000)
total=0
while (num != 0)
{
total=total+num%10
num=num/10
}

printf("%d", total);
}```
what is wrong with num being used for divisible by 10?

2. You can't use &#37; on a float.
The operands of the % operator shall have integer type.

3. then wat should i use to make a float or a double divisible by a certain number?
casting it to an int would make the program work but give me the wrong value.

How would u have a double or a float divisible by a certain number?

4. Use fmod()

5. thanks man, but wat would be the 1st and 2nd parameters since it asks for them?
num as the 1st and 10 as the 2nd as when i tried that it gives me:
undefined reference to 'fmod' collect 2: ld returned 1 exit status.

6. The first is the numerator and the second is the denominator. Use google to get actual documentation. Remember google is your friend !!

7. I did, it just said numerator and dominator, but im not sure what would be the denomiator would be

8. n/d => n=numerator d=denominator

9. so then i would just do num/10 then?
that would make it divisible by ten? as that just sounds like it would be
num divided by 10, instead of num divisible 10

10. i can't use anything anything for that?

11. You can use the following:
Code:
```float num;
int remainder;
num = 12345.6789f;
remainder = floor(num - (int)( ( num / 10 ) * 10 ));```
It should work for positive floats... and you might like round better, instead of floor.

12. Thanks bud and everyone else for ur help! That absolutely worked!

13. Originally Posted by OxKing033
then wat should i use to make a float or a double divisible by a certain number?
If x and y are floats, and x / y is an integer (or extremely close to one), then x is divisible by y. You could you fmod() too.