#include <stdio.h>
#define TAXBASE 3500
/* Define the structure */
typedefstruct
{
long start;
long end;
double taxrate;
}TAXTABLE;
/* Define structure array */
TAXTABLE TaxTable[] ={{0, 1500, 0.03}, {1500, 4500, 0.10}, {4500, 9000, 0.20}, {9000, 35000, 0.25}, {35000, 55000, 0.30}, {55000, 80000, 0.35}, {80000, 1e10, 0.45}};
/*CaculateTax() function */
double CaculateTax(long profit)
{
int i;
double tax = 0.0;
profit -= TAXBASE;
for (i = 0; i < sizeof(TaxTable)/sizeof(TAXTABLE); i++)
{
if (profit > TaxTable[i].start)
{
if (profit > TaxTable[i].end) {
tax += (TaxTable[i].end - TaxTable[i].start)*TaxTable[i].taxrate;
}
else
{
tax += (profit - TaxTable[i].start)*TaxTable[i].taxrate;
}
profit -= TaxTable[i].end;
printf("征税范围:%ld ~ %ld\n该范围内缴税金额:%3.2f\n超出该范围的金额:%ld\n", TaxTable[i].start, TaxTable[i].end, tax, (profit)>0 ? profit:0);
}
}
return tax;
}
int main(int argc, const char * argv[])
{
long profit;
double tax;
//printf("%lu,%lu",sizeof(TAXTABLE), sizeof(TaxTable));
printf("请输入个人收入金额:\n");
scanf("%ld", &profit);
tax = CaculateTax(profit);
printf("您的个人所得税为:%.2f\n", tax);
return 0;
}