本程序是为了帮助大家计算个人所得税的。

#include<stdio.h>
int main()
{
	double tax, rate;
	int deduction, salary, flag;
	printf("Enter the salary: ");
	scanf("%d", &salary);
	if (salary <= 3500)
	{
		rate = 0;
		deduction = 0;
		tax = rate * (salary - 3500) - deduction;
		printf("tax=%.2f\n", tax);
	}
	else
	{
		flag = (salary > 3500) + (salary > 5000) + (salary > 8000) + (salary > 12500) + (salary > 38500) + (salary > 58500) + (salary > 83500);
		switch (flag)
		{
		case 1:
		{
			rate = 0.03;
			deduction = 0;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n", tax);
			break;
		}
		case 2:
		{
			rate = 0.10;
			deduction = 105;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n", tax);
			break;
		}
		case 3:
		{
			rate = 0.20;
			deduction = 555;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n", tax);
			break;
		}
		case 4:
		{
			rate = 0.25;
			deduction = 1005;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n",tax);
			break;
		}
		case 5:
		{
			rate = 0.30;
			deduction = 2755;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n", tax);
			break;
		}
		case 6:
		{
			rate = 0.35;
			deduction = 5505;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n", tax);
			break;
		}
		case 7:
		{
			rate = 0.45;
			deduction = 13505;
			tax = rate * (salary - 3500) - deduction;
			printf("tax=%.2f\n", tax);
			break;
		}
		}

	}
	return 0;
}

本程序是为了帮助大家计算个人所得税的。

本文章有一个亮点就是帮助在使用switch时,我进行了关系运算符,来确定常量,这样不仅符合了switch的用法更便于使用,如果用if—else不便于代码的优化。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值