为什么不能正常赋值?
刚才尝试将一个if-else结构的语句转化成开关语句,但是发现K不能正常赋值 运行结果是K=0;K=0; 修改了几次,还是这样的结果。请问各位大神,具体是哪儿的原因呢?
#include <stdio.h>
void main()
{
long int i;
int x;
double K,K1,K2,K4,K6,K10;
printf("please input money:\n");
scanf("%ld",&i);
x=i/100000;
K1=100000*0.1;
K2=K1+100000*0.075;
K4=K2+200000*0.05;
K6=K4+200000*0.03;
K10=K6+400000*0.015;
switch(x)
{
case 0:
K=i*0.1;printf("K=%d\n",K);break;
case 1:
K=K1+(i-100000)*0.075;break;
case 2:
case 3:
K=K2+(i-200000)*0.05;break;
case 4:
case 5:
K=K4+(i-400000)*0.03;break;
case 6:
case 7:
case 8:
case 9:
K=K6+(i-600000)*0.015;break;
default:
K=K10+(i-1000000)*0.01;break;
}
printf("K=%d\n",K);
}