个人所得税问题

发布时间 2023-04-22 21:13:42作者: Hbro

1.问题描述:

    编写一个计算个人所得税的程序,要求输入收入金额后能够输出应缴的个人所得税。个人所得税的征收办法如下

2.思路

   1.建立结构体 其中包含 start(起始税费),end(阶段最大税费),taxrate(税率);

   2.写出计算函数 tax += (p->end - p->start) * p->taxrate;(当个人所得税大于阶段税费最大值的时候)

     tax = (profit - p->start) * p->taxrate;(税率小于阶段税费最大值); 

#include<iostream>
#define taxbase 3500
using namespace std;
typedef struct
{
double start;
double end;
double taxrate;
}Tax;
Tax tax[] = { {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} };
double caculate(double profit) {
Tax* p;
double taxx = 0.0;
profit -= taxbase;
for (p = tax; p < tax + sizeof(tax) / sizeof(Tax); p++) {
if (profit > p->start) {
if (profit > p->end) {
taxx += (p->end - p->start) * p->taxrate;
}
else {
taxx += (profit - p->start) * p->taxrate;
}
profit -= p->end;
double num = (profit) > 0 ? profit : 0;
cout << "征税范围:" << p->start << "---" << p->end << " " << "该范围内交税金额:" << taxx << " " << "超出该范围金额:" << num;
cout << endl;
}
}
return taxx;
}
int main()
{
double profit;
double tax;
cout << "请输入个人收入金额:";
cin >> profit;
tax = caculate(profit);
cout << "您的个人所得税为:" << tax;
return 0;
}