C++中“left operand has type 'float'”是种什么错误? 10
#include<iostream>usingnamespacestd;voidmain(){inta,b,n=0,s=0;floatc,d;b=a+1;c=a*b-1;...
#include <iostream>
using namespace std;
void main()
{int a,b,n=0,s=0;
float c,d;
b=a+1;
c=a*b-1;
for(a=2;a<=49;a++)
{
for(d=2;d<c;d++)
if(c%d!=0)
{
n+=1;
s+=c;
}
}
cout<<n<<endl;
cout<<s<<endl;
}
结果显示:(11) : error C2296: '%' : illegal, left operand has type 'float'
(11) : error C2297: '%' : illegal, right operand has type 'float'
该如何修改? 展开
using namespace std;
void main()
{int a,b,n=0,s=0;
float c,d;
b=a+1;
c=a*b-1;
for(a=2;a<=49;a++)
{
for(d=2;d<c;d++)
if(c%d!=0)
{
n+=1;
s+=c;
}
}
cout<<n<<endl;
cout<<s<<endl;
}
结果显示:(11) : error C2296: '%' : illegal, left operand has type 'float'
(11) : error C2297: '%' : illegal, right operand has type 'float'
该如何修改? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询