0

I'm new to C++ and is trying to learn the concept of arithmetic operators. Could someone please tell me why statement 1 is legal while statement 2 is illegal?

Statement 1:

double v1 = (double)51/4;

Statement 2:

double v2 = ((double)51/4)%2;
Thor
  • 9,638
  • 15
  • 62
  • 137

1 Answers1

1

In statement 2 you are using the modulus operator % on a double and an integer, however the modulus operator only works on integer-values.

More info here: Can't use modulus on doubles?

Community
  • 1
  • 1
FrederikDS
  • 96
  • 7