个税计算器

个人所得税计算,这里还是原来的9级税率,新的个税已经是7级的了。

#ifndef _TAX_CONFIG_H_
#define _TAX_CONFIG_H_

typedef struct tax_rate
{
	int income_floor;
	int income_ceiling;
	float rate;
	int sub_value;
} tax_rate_t;

// personal tax start value
const int PERSONAL_TAX_START=2000;

// personal tax rate table
const tax_rate_t PERSONAL_TAX_RATE_TABLE[9] = 
{
	{0, 500, 0.05, 0},
	{500, 2000, 0.1, 25},
	{2000, 5000, 0.15, 125},
	{5000, 20000, 0.2, 375},
	{20000, 40000, 0.25, 1375},
	{40000, 60000, 0.3, 3375},
	{60000, 80000, 0.35, 6375},
	{80000, 100000, 0.4, 10375},
	{100000, -1, 0.45, 15375}
};

#endif //_TAX_CONFIG_H_

#include <stdio.h>
#include <stdlib.h>

#include "tax_config.h"

float personal_tax(int income);

int main(int argc, char *argv[])
{
	if (argc < 2)
	{
		printf("Usage: %s income", argv[0]);
		return -1;
	}
	printf("Your tax: %d\n", personal_tax(atoi(argv[1])));
	
	return 0;
}

int personal_tax_rate_table_index(int extra_income)
{
	for (int i = 0; i < sizeof(PERSONAL_TAX_RATE_TABLE) / sizeof(PERSONAL_TAX_RATE_TABLE[0]); i++)
	{
		if (PERSONAL_TAX_RATE_TABLE[i].income_floor <= extra_income 
        && extra_income < PERSONAL_TAX_RATE_TABLE[i].income_ceiling)
			return i;
	}
	return i;
}

float personal_tax(int income)
{
	int extra_income = income - PERSONAL_TAX_START;
	int index = personal_tax_rate_table_index(extra_income);
	float tax = extra_income * PERSONAL_TAX_RATE_TABLE[index].rate 
                - PERSONAL_TAX_RATE_TABLE[index].sub_value;
	return tax;
}


  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值