2.1 个人所得税问题

第一部曲:

 利用结构体存储个人所得税范围还有税率然后进行运算。

第二部曲:

 

第三部曲:

typedef struct
{
long start;
long end;
double taxrate;
}TAXTABLE;
TAXTABLE TaxTable[]={{0,1500,0.3},{1500,4500,0.10},{4500,9000,0.20},{9000,35000,0.25},{35000,55000,0.30},{55000,80000,0.35},{80000,100000,0.45}};

第四步曲:

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define TAXBASE 3500
typedef struct
{
long start;
long end;
double taxrate;
}TAXTABLE;
TAXTABLE TaxTable[]={{0,1500,0.3},{1500,4500,0.10},{4500,9000,0.20},{9000,35000,0.25},{35000,55000,0.30},{55000,80000,0.35},{80000,100000,0.45}};
double caculate(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("征税范围:%6ld~%6ld 该范围内交税金额:%6.2f 超出该范围的金额:%6ld\n",TaxTable[i].start,TaxTable[i].end,tax,(profit)>0?profit:0);
}
}
return tax;
}
int main()
{
long profit;
double tax;
scanf("%ld",&profit);
tax=caculate(profit);
cout<<tax;
return 0;
}

 

posted @ 2023-04-27 22:21  自律小子丶  阅读(15)  评论(0)    收藏  举报