个人所得税问题

发布时间 2023-04-16 12:28:43作者: 不如喝点

个人所得税问题:

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

起征点为3500元。

不超过1500元的部分,征收3%;

超过1500~4500元的部分,征收10%;

超过4500~9000元的部分,征收20%;

超过9000~35000元的部分,征收25%;

超过35000~55000元的部分,征收30%;

超过55000~80000元的部分,征收35%;

超过80000元以上的,征收45%。

解题思路:

输入收入金额,利用设计的函数算出个人所得税然后输出。函数中根据收入与每一部分的前后金额比较来判断是否有税,然后输出每部分的税收以及超出该部分的金额

代码:

#include<iostream>

#include<iomanip>

using namespace std;

# define taxbase 3500

struct taxtable

{

    int x;

    long int y;

    double z;

};

taxtable a[]={{0,1500,0.03},{1500,4500,0.1},{4500,9000,0.2},{9000,35000,0.25},{35000,55000,0.3},{55000,8000,0.35},{80000,1000000000,0.45}};

double caculate(int profit)

{

    double tax=0;

    profit-=taxbase;

    for(int i=0;i<sizeof(a)/sizeof(a[1]);i++)

    {

        if(profit>a[i].x)

        {

            if(profit>a[i].y)

                tax+=(a[i].y-a[i].x)*a[i].z;

            else

                tax+=(profit-a[i].x)*a[i].z;

            profit-=a[i].y;

            cout<<"征税范围:"<<setw(6)<<a[i].x<<"~"<<setw(6)<<a[i].y<<"  该范围内缴税金额:  "<<setw(6)<<setiosflags(ios::fixed)<<setprecision(2)<<tax<<"  超出该范围的金额:  ";

            if(profit>0)

                cout<<setw(6)<<profit<<endl;

            else

                cout<<"     0"<<endl;

        }

    }

    return tax;

}

int main()

{

    int profit;

    double tax;

    cout<<"请输入个人所得金额:"<<endl;

    cin>>profit;

    tax=caculate(profit);

    cout<<"您的个人税收为:"<<setw(12)<<setiosflags(ios::fixed)<<setprecision(2)<<tax<<endl;

    return 0;

}

该题体会:可以利用结构体来储存多组数据以及c++中如何控制输出小数位数的方法