if (operation = '+' || operation = '-' || operation = '*' || operation = '/' || operation = '%')//error line
{
printf("Enter the first operand:\t\t");
getchar();
scanf("%d", &num1);
printf("Enter the second operand:\t\t");
getchar();
scanf("%d", &num2);
}
它给出了一个错误说:
Error: expresion must be a modifiable value
它给了我关于那条 if 行的错误,关于所有的参数,除了那个说的那个
operation = '%'
问题是什么?? 谢谢你们:)
最佳答案
你打错了,你写了赋值运算符 =
而不是比较运算符 ==
代替
if (operation = '+' || operation = '-' || operation = '*' || operation = '/' || operation = '%')
必须有
if (operation == '+' || operation == '-' || operation == '*' || operation == '/' || operation == '%')
您可以将 if 语句写得更简单。例如
const char *Operations = "+-*/%";
char *p = strchr( Operations, operation );
if ( p != NULL )
{
printf("Enter the first operand:\t\t");
getchar();
scanf("%d", &num1);
printf("Enter the second operand:\t\t");
getchar();
scanf("%d", &num2);
}
甚至不声明指针 p
const char *Operations = "+-*/%";
if ( strchr( Operations, operation ) != NULL )
{
printf("Enter the first operand:\t\t");
getchar();
scanf("%d", &num1);
printf("Enter the second operand:\t\t");
getchar();
scanf("%d", &num2);
}
关于c - (c) 表达式必须是可修改的左值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26945802/