I'm getting a compilation error using fmod to split the int from the remainder.
error: passing 'int *' to parameter of incompatible type 'double'

Here's the code:

 // definitions

float da, F;
int I, F2, Q1;

while (da > 0.00)           
    F = modf (da, &I);
    F2 = round (F * 100);
    Q1 = I / .25;  

printf("Integer %d and rounded remainder %d", I, Q1)

1 Answer 1


floats and doubles are not precise. Better work with ints! After you receive the input from the user, convert it to cents and round it to the nearest integer using a function like round() from the math library immediately!

As for your compilation error, modf() accepts a double and a pointer to a double (aka a double *). You're passing a float and a pointer to an int (aka int *) instead.

  • Why is the pointer a double when it's the integer part of the input
    – Mo1
    Aug 9, 2014 at 19:08
  • So if I change F to double, it should work?
    – Mo1
    Aug 9, 2014 at 19:08
  • @Mo1 that's what the function requires -- a double and a pointer to a double! And again, floats are not precise anyway, you shouldn't work with floats nor doubles. Just get the user input and convert it to an int immediately after multiplying by 100 and rounding the result to the nearest int using round()!
    – kzidane
    Aug 9, 2014 at 19:15
  • Thanks but I want to get it working this way first. I understand the issues with float but modf seemed fun to try. I wasn't sure if it was only double.
    – Mo1
    Aug 10, 2014 at 2:16
  • @Mo1 feel free to try! In fact I encourage that! But probably you won't succeed getting it working! At least not with all inputs.
    – kzidane
    Aug 10, 2014 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .