#include<stdio.h>
main()
{
double a,b;
scanf("%d",&a);
if(a>10000) { b=a*0.05; printf("The tex is %d.\n",b);}
else if(a<10000&&a>5000) {b=0.03*a;printf("The tex is %d.\n",b); }
else if(a<5000&&a>1000) {b=0.02*a;printf("The tex is %d.\n",b );}
else {printf("The tex is %d.\n",a);}
}
对于double变量,相应的格式符不能用 %d,应为 %lf,改正后的程序见下:
#include<stdio.h>
main()
{
double a,b;
scanf("%lf",&a);
if(a>10000) { b=a*0.05; printf("The tex is %lf.\n",b);}
else if(a<10000&&a>5000) {b=0.03*a;printf("The tex is %lf.\n",b); }
else if(a<5000&&a>1000) {b=0.02*a;printf("The tex is %lf.\n",b );}
else {printf("The tex is %lf.\n",a);}
}
程序的一种运行结果如下(其它几种情况,你可自行运行):
一周热门 更多>