请问,用devc++编辑时遇到这种情况时怎么回事?不知道有什么语法问题
#include<stdio.h>
#include<math.h>
int main(){
int x=500,w;
long int p;
scanf("%ld",&p);
if(p<=1000) {printf("%d",x);}
else if(p>1000&&p<=2000) {printf("%d",w=x*(1+10%));}
else if(p>2000&&p<=5000) {printf("%d",w=x*(1+15%));}
else if(p>5000&&p<=10000) {printf("%d",w=x*(1+20%));}
else {printf("%d",w=x*(1+25%));}
return 0;
}
系统一直报错expected expression before ')'token
大一刚接触c语言,请问为什么会expected expression before ')'token
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
kayilv 2022-10-05 16:33关注你的输出语句中的这个w=x*(1+10%)其实是错的,%是求余符号,而不是数学中的百分号,你用错了,如果你想表达百分之十你可以用0.1来表示。当然,这样的化你需要修改你前面w的数据类型,改成double。同时修改%d为%lf。
而且虽然赋值表达式语句的值就是其右值,也就是说a=2+4;这个赋值语句它本身的值是6.
但这样写难免有些画蛇添足了,不如试试下面的写法:#include<stdio.h> #include<math.h> int main() { double x=500.0; long int p; scanf("%ld", &p); if (p <= 1000) { printf("%lf", x); } else if (p > 1000 && p <= 2000) { printf("%lf", x * (1 + 0.1 )); } else if (p > 2000 && p <= 5000) { printf("%lf", x * (1 + 0.15 )); } else if (p > 5000 && p <= 10000) { printf("%lf", x * (1 + 0.2 )); } else { printf("%lf", x * (1 + 25 )); } return 0; }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报