请问,用devc++编辑时遇到这种情况时怎么回事?不知道有什么语法问题
#include
#include
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
你的输出语句中的这个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;
}
把print里面的w=都删掉..
应该是传递一个值
%d用来输出一个整形,把这些语句拎出去