[求助]switch的问题
要求是在 I<= 100000时,i=I*0.1,100000< I <= 200000时,i = 100000 * 0.1 + (I - 100000) * 0.075,200000< I <= 400000时,i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05,400000< I <= 600000时,i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03,600000<I <= 1000000时,i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015,用switch语句来做。我做这个有问题,如果大家有更好的办法,或者能改正这个都行,谢谢了
#include<stdio.h>
void main()
{
int I, x;
float i;
printf("Please enter the profit: \n");
scanf("%d", &I);
x = I/100000;
switch(x)
{
case'0': printf("The praise of the year is %f\n", i = I * 0.1);
break;
case'1': printf("The praise of the year is %f\n", i = 100000 * 0.1 + (I - 100000) * 0.075);
break;
case'2': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05);
break;
case'3': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05);
break;
case'4': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03);
break;
case'5': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03);
break;
case'6': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'7': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'8': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'9': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'10': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
}
}