计算个人所得税的c语言程序

#define TAXBASE  3500

typedef struct{
	long base;
	long limit;
	double taxrate;
}TAXTABLE;

TAXTABLE TaxTable[] = {
	{0,     1500,   0.03},
	{1500,  4500,   0.1},
	{4500,  9000,   0.2},
	{9000,  35000,  0.25},
	{35000, 55000,  0.3},
	{55000, 80000,  0.35},
	{80000, 1e10,   0.45},	
};

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].base )
		{
			if( profit > TaxTable[i].limit )
			{
				tax += (TaxTable[i].limit - TaxTable[i].base) * TaxTable[i].taxrate;
			}
			else
			{
				tax += (profit - TaxTable[i].base) * TaxTable[i].taxrate;
			}
		
			printf("Base%d:%6ld Limit%d:%6ld  Tax:%12.2f Leave:%6ld\n",i,TaxTable[i].base,i,\
				TaxTable[i].limit, tax, (profit)>0 ? profit : 0);
		}
	}
	return tax;
}

int main(void)
{
	long profit;
	double tax;
	scanf("%ld",&profit);
	tax = CaculateTax(profit);
	printf("Tax is: %12.2f\n",tax);
	return 0;
}

 

你可能感兴趣的:(小程序)