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;
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;
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?