invalid operands of types int and double to binary 'operator%'

前端 未结 3 796
南方客
南方客 2021-01-03 21:29

After compiling the program I am getting below error

invalid operands of types int and double to binary \'operator%\' at line 
\"newnum1 = two % (double)10.0         


        
相关标签:
3条回答
  • 2021-01-03 21:59

    Because % only works with integer types. Perhaps you want to use fmod().

    0 讨论(0)
  • 2021-01-03 22:18

    Because % is only defined for integer types. That's the modulus operator.

    5.6.2 of the standard:

    The operands of * and / shall have arithmetic or enumeration type; the operands of % shall have integral or enumeration type. [...]

    As Oli pointed out, you can use fmod(). Don't forget to include math.h.

    0 讨论(0)
  • 2021-01-03 22:18

    Yes. % operator is not defined for double type. Same is true for bitwise operators like "&,^,|,~,<<,>>" as well.

    0 讨论(0)
提交回复
热议问题