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;"
Why is it so?
#include<iostream>
#include<math>
using namespace std;
int main()
{
int num;
double two = 1;
double newnum, newnum1;
newnum = newnum1 = 0;
for(num = 1; num <= 50; num++)
{
two = two * 2;
}
newnum1 = two % (double)10.0;
newnum = newnum + newnum1;
cout << two << "\n";
return 0;
}
Because
%is only defined for integer types. That’s the modulus operator.5.6.2 of the standard:
As Oli pointed out, you can use
fmod(). Don’t forget to includemath.h.