错误:C++ 中二进制"operator%"类型"float"和"int"的操作数无效
error: invalid operands of types 'float' and 'int' to binary 'operator%' in c++
几周前刚开始在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;
理想情况下,程序应在屏幕上显示代表算术平均值的数字"f"。
% 运算符不是为实数定义的 - 您希望在 <cmath>
中声明 fmod() 函数。请参阅 http://en.cppreference.com/w/cpp/numeric/math/fmod
相关文章:
- 错误:从"int"到枚举c++的转换无效
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 从 'int' 到 'int*' CPP 的转换无效
- 无效 f(int) 的模板和 decltype
- 错误:从"int"到"int*"的转换无效[-允许].我在下面提供了我的代码,我
- 错误:数组下标的类型"int[int]"无效
- int* 和 int[] 类型对二进制运算符 + 的操作数无效
- 从类指针到 int 的转换无效
- C++ 错误:由于 swprintf 而从 'int' 到 'const wchar_t* 的转换无效
- 为什么 std::d eclval<int>() = std::d eclval<int>() 无效?
- 错误:数组下标的类型"const bool[int]"无效
- 2D数组中数组下标的类型"int[int]"无效
- 错误:数组下标的类型'int[int]'无效
- C++中的合并排序:无法在合并函数中传递数组 - 转换为'int*'无效
- 数组下标的类型"int[int]"无效
- 使用矢量的数组下标'int[int]'无效类型
- C++中的二进制补码 - 数组下标的类型"int[int]"无效
- 从“char*”到“char”[-fpermissive]的转换无效,数组下标的类型“char[int]”无效
- 无法解决错误:间接寻址需要指针操作数("int"无效)
- C++将数组相互分配;type int*=type int有效,但int=int*无效