【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
我的代码哪错了?显示的是:ex1.c:7:10: error: switch quantity not an integer
ex1.c:9:2: error: case label does not reduce to an integer constant
ex1.c:12:2: error: case label does not reduce to an integer constant
ex1.c:15:2: error: case label does not reduce to an integer constant
#include <stdio.h>
main()
{
float x,y;
prntf("plese input a count for x:");
scanf("%f",&x);
switch (x)
{
case x<1:
y = x;
break;
case x>=1||x<10:
y = 2*x - 1;
break;
case x>=10:
y = 3*x - 11;
}
printf("the result 'y' is :%f\n",y);
return 0;
}
switch quantity not an integer (case 后面就整型和字符型变量,不要用 float型)
The expression of each case label shall be an integer constant expression and no two of
the case constant expressions in the same switch statement shall have the same value
after conversion.
c99标准。