The modulus operator can only be applied to integral types. To compute the remainder of two floating point variables, you have to use the fmod() function instead. Fmod() is declared in <cmath> (formerly: <math.h>) as follows:
double fmod(double x, double y);
fmod() calculates x modulo y, which is the remainder of x/y. When y is 0, fmod() returns 0.
The Standard Library defines another version of this function called fmodl(), which is identical to fmod() except that it takes and returns variables of type long double.