C语言问题急需解决

来源:百度知道 编辑:UC知道 时间:2021/01/21 20:16:07
1.编写一个计算个人所得税的程序,要求,输入一个职工的月工资salary,输出按照现行个人所得税标准计算的个人所得税tax。要求用switch语句。
现行所得税税率如下,并采取分段税收法。
salary < 1000, rate = 0% 1000<= salary < 1500,rate = 5%
1500<= salary < 2500, rate = 10% 2500<= salary < 3500, rate = 15%
3500<= salary < 5000, rate = 20% salary >= 5000, rate = 30%
提示:switch中的表达式可以写为(int)(salary/500)

main()
{
float salary, rate;
scanf("%lf",&salary);
switch((int)(salary/500))
{
case 0::rate = 0; break;
case 1:
case 2: rate = 0.5; break;
case 3:
case 4: raet = 0.1; break;
case 5:
sase 6: rate = 0.15; break;
case 7:
case 8:
case 9: rate = 0.2; break;
default
rate = 0.3; break;
}
printf("%lf*%lf=%lf", rate,salary, salary*rate)
}

#include "stdio.h"
void main()
{
float salary;
float rate;
scanf("%f",&salary);
switch((int)(salary/500-1))
{
case 0:rate=0;break;
case 1:rate=salary*0.05;break;
case 2:rate=salary*0.1;break;
case 3:rate=salary*0.1;break;
case 4:rate=salary*0.15;break;
case 5:rate=salary*0.15;break;
case 6:rate=salary*0.2;break;
case 7:rate=salary*0.2;break;
case 8:rate=salary*0.2;break;
default:
rate=salary*0.3;break;
}
printf("%5.2f",rate);
}