if语句是对的 但switch语句就错了?急啊!!
算工资的问题 I 代表个人对公司带来的利润 Q 代表工资这是我用if语句写的是对的
main()
{
float I,Q;
scanf("%f",&I);
if(I<0)printf("it is not riight\n");
else{
if(I<=100000)Q=0.1*I;
else if(I<=200000)Q=0.1*100000+0.075*(I-100000);
else if(I<=400000)Q=0.1*100000+0.075*100000+0.05*(I-200000);
else if(I<=600000)Q=0.1*100000+0.075*100000+0.05*200000+0.03*(I-400000);
else if(I<=1000000)Q=0.1*100000+0.075*100000+0.05*200000*0.03*200000+0.015*(I-
600000);
else Q=0.1*100000+0.075*100000+0.05*200000+0.03*200000+0.015*400000+
0.01*(I-1000000);
printf("Q=%f\n",Q);
}
}
下面用switch语句写的就是错的?能帮我看下错在哪里?
main()
{
float I,Q;int t;
scanf("%f",&I);
if(I<0)printf("it is not right\n");
else{
if(I>=1000000)Q=0.1*100000+0.075*100000+0.05*200000+0.03*200000+0.015*400000+0.01*(I-1000000);
else t=I/100000;
switch(t)
{
case 0:Q=0.1*I;break;
case 1:Q=0.1*100000+0.075*(I-100000);break;
case 2:
case 3:Q=0.1*100000+0.075*100000+0.05*(I-200000);break;
case 4:
case 5:Q=0.1*100000+0.075*100000+0.05*200000+0.03*(I-400000);break;
case 6:
case 7:
case 8:
case 9:Q=0.1*100000+0.075*100000+0.05*200000+0.03*200000+0.015*(I-1000000);break;
}
printf("Q=%f\n",Q);
}
}
}
[ 本帖最后由 TERMINATORXQ 于 2009-11-14 23:39 编辑 ]