编译我收到以下错误类型的无效操作数int和double二进制“操作符%”
invalid operands of types int and double to binary 'operator%' at line
"newnum1 = two % (double)10.0;"
程序后,为什么会这样呢?
#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;
}
'(double)10.0'这个类型转换不做任何事情。 10.0已经是双重类型。 10.0f是浮点类型,10是(带符号)整数类型。 – Lundin 2012-02-14 14:33:40
@Lundin:'10'具体是'int'类型,而不是任何任意有符号整数类型。 – 2016-01-07 19:32:41