While trying to compile the codes uploaded I keep having this error which I couldn't understand!enter image description here

1 Answer 1


% operator is used to perform binary operation on integer or integer-like operands. It is used like this:

int i,j;
input i , j
i = i % j;
print i

What you are trying to achieve is something similar to this:

double i,j;
input i , j
i = i % j;
print i

The problem is what do expect it to output when dealing with floating point numbers? For eg. 54.66 % 1.02 gives no sense. And that's what the error says, invalid operands to binary expression.

  • can you explain more, sorry but I cant understand Aug 10, 2014 at 0:58
  • and I am not using any float variable in the code ! Aug 10, 2014 at 0:58
  • I suppose you are using double in your code, that too will give the same error
    – sinister
    Aug 10, 2014 at 2:06
  • so isnt there any solution for this problem ? I am using long not double by the way but after all its not an integer Aug 10, 2014 at 13:06
  • 1
    pow() returns a double so you are implicitly using a double in the %, did you try an explicit cast to long (or long long)? So something like: number1 % ((long)pow(10,i)) ?
    – stefjan
    Sep 12, 2014 at 16:42

You must log in to answer this question.

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