第8周项目4-个人所得税计算器(if~else~语句+switch语句)

  1. /*  
  2.  * Copyright (c) 2014, 烟台大学计算机学院  
  3.  * All rights reserved.  
  4.  * 文件名称:test.cpp  
  5.  * 作    者:刘畅   
  6.  * 完成日期:2014年 10 月 16 日  
  7.  * 版 本 号:v1.0  
  8.  *  
  9.  * 问题描述:输入个人月收入总额,通过“个人所得税=(收入总额-3500)*税率-速算扣除数”和“税后收入=收入总额-个人所得税”,计算出他本月应缴税款和税后收入;
  10. * 输入描述:输入个人月收入总额dSalary,且(在switch语句中)用a代表税率,用b代表速算扣除数
  11.  * 程序输出:输出本月应缴税款dTax和税后收入dNetIncome。
  12. */
  13. (1)if~else~语句:
  14. #include <iostream>
    using namespace std;
    int main()
    {
        double dSalary,  dTax = 0, dNetIncome = 0;
        cout << "请输入您本月的收入总额(元):";
        cin >> dSalary;
        int x;
        if (dSalary < 3500)
        {
            cout << "您不需要纳税,谢谢使用!\n";
            return 0;
        }
        else
            x = dSalary - 3500;
        if (x <= 1500)
        {
            dTax = (dSalary - 3500) * 0.03;
            dNetIncome = dSalary - dTax;
        }
        else if (x <= 4500)
        {
            dTax = (dSalary - 3500) * 0.10 - 105;
            dNetIncome = dSalary - dTax;
        }
        else if (x <= 9000)
        {
            dTax = (dSalary - 3500) * 0.20 - 585;
            dNetIncome = dSalary - dTax;
        }
        else if (x <= 35000)
        {
            dTax = (dSalary - 3500) * 0.25 - 1005;
            dNetIncome = dSalary - dTax;
        }
        else if (x <= 55000)
        {
            dTax = (dSalary - 3500) * 0.30 - 2755;
            dNetIncome = dSalary - dTax;
        }
        else if (x <= 80000)
        {
            dTax = (dSalary - 3500) * 0.35 - 5505;
            dNetIncome = dSalary - dTax;
        }
        else
        {
            dTax = (dSalary - 3500) * 0.45 - 13505;
            dNetIncome = dSalary - dTax;
        }
        cout << "您本月应缴个人所得税" << dTax << "元,税后收入是"
             << dNetIncome << "元。\n";
        cout << "依法纳税,共享繁荣。谢谢使用!\n";
        return 0;
    }
     
  15.  
  16. (2)switch语句:

  17. #include <iostream>
    using namespace std;
    int main()
    {
        double dSalary,  dTax = 0, dNetIncome = 0,x,a;
        int t,b;
        cout << "请输入您本月的收入总额(元):";
        cin >> dSalary;
        x=dSalary-3500;
        t=(x<=1500)+(x<=4500)+(x<=9000)+(x<=35000)+(x<=55000)+(x<=80000);
        switch (t)
        {
        case 6:
            a=0.03,b=0;
            break;
        case 5:
            a=0.10,b=105;
            break;
        case 4:
            a=0.20,b=555;
            break;
        case 3:
            a=0.25,b=1005;
            break;
        case 2:
            a=0.30,b=2755;
            break;
        case 1:
            a=0.35,b=5505;
            break;
        default:
            a=0.45,b=13505;
        }
        dTax=x*a-b;
        dNetIncome=dSalary-dTax;
        cout << "您本月应缴个人所得税" << dTax << "元,税后收入是"
             << dNetIncome << "元。\n";
        cout << "依法纳税,共享繁荣。谢谢使用!\n";
        return 0;
    }

     
  18.  
  19. 运行结果:
  20.  
  21.   
  22.  
  23. 知识点总结:
  24.  成功的在if~else~嵌套和switch语句上迈出了一大步,要充分掌握好switch语句的运用,在这种长代码中感觉还是switch好用。
  25.  
  26. 学习心得:
  27. 越发感觉到编出一个成功的程序后是多么快乐,继续加油!!
  28. 昨晚的辛苦没有白费,只是实在没有那么多精力去打那些注释了,敬请见谅;不理解的可以在下面评论栏中留言;谢谢。
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值