个人所得税计算,这里还是原来的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;
}