I get an error: lvalue required as left operand of assignment
I get an error: lvalue required as left operand of assignment
我收到这个错误,我是这个编码的初学者,所以我知道的不多。这是我的程序:
#include <iostream> 1
using namespace std; 2
int a,b,k,i,n,c; 3
int main() 4
{ 5
cin>>a>>b; 6
k=0; 7
for (i=a;i<=b;i=i+1) 8
{ 9
n=i; 10
c=0; 11
while (n>0) 12
{ 13
if (n%2=1) 14
c=c+1; 15
n=n/10; 16
} 17
if (c>0) 18
k=k+1; 19
} 20
cout<<k; 21
22
return 0; 23
} 24
错误似乎在第 14 行!
我正在使用 Code::Blocks 版本 13.12
您在第 14 行使用了一个“=”,但这仅用于赋值。您正在进行 if 比较,因此您必须使用“==”。
if (n % 2 == 1)
我收到这个错误,我是这个编码的初学者,所以我知道的不多。这是我的程序:
#include <iostream> 1
using namespace std; 2
int a,b,k,i,n,c; 3
int main() 4
{ 5
cin>>a>>b; 6
k=0; 7
for (i=a;i<=b;i=i+1) 8
{ 9
n=i; 10
c=0; 11
while (n>0) 12
{ 13
if (n%2=1) 14
c=c+1; 15
n=n/10; 16
} 17
if (c>0) 18
k=k+1; 19
} 20
cout<<k; 21
22
return 0; 23
} 24
错误似乎在第 14 行! 我正在使用 Code::Blocks 版本 13.12
您在第 14 行使用了一个“=”,但这仅用于赋值。您正在进行 if 比较,因此您必须使用“==”。
if (n % 2 == 1)