[英]error: invalid operands of types 'float' and 'int' to binary 'operator%' in c++
Just started programing in C++ a few weeks ago and I encountered this problem: 几周前刚开始用C ++编程,我遇到了这个问题:
float a,i,b,c,d,e,f;
cin>>a;
cin>>c;
if(c%2==0)
{
d=c;
e=1;
}
else
{
d=0;
e=0;
}
for (i=2;i<=a;i++)
{
cin>>b;
if(b%2==0)
{
d=d+b;
e=e+1;
}
}
f=d/e;
if(e==0)
cout<<"0";
else
cout<<fixed<<setprecision(2)<<f;
Ideally, the program should display on the screen the number "f" representing the arithmetic average. 理想情况下,程序应在屏幕上显示代表算术平均值的数字“ f”。
The % operator is not defined for real numbers - you want the fmod() function declared in <cmath>
. 未为实数定义%运算符-您需要在
<cmath>
声明fmod()函数。 See http://en.cppreference.com/w/cpp/numeric/math/fmod 参见http://en.cppreference.com/w/cpp/numeric/math/fmod
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.