栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言薪资计算程序

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言薪资计算程序

##薪资计算程序
##计算税前工资、应交所得税、税后工资
##代码中的税率不代表真实税率
##请勿盲目相信

#include 
#define OVERTIME 1.5                              //working time over40, time =1.5*time
#define RATE_LESS_300 0.15                        //tax rate
#define RATE_MORE_300_LESS_450 0.15
#define RATE_MORE_450 0.25
//this function is used to give user choices of salary per hour
//and return the basic salary per hour
//if user input number not 1~4
//whole program would over
float basic_salary(void);                         //function declaration
int main(void)
{
    float wage = 0, tax = 0, hours = 0,BASIC=0;   //BASIC--- basic salary/wage
   
    BASIC = basic_salary();
    if (BASIC==-1)
        return -1;
    printf("Please input your working hours(q to quit): ");
    while (scanf("%f", &hours) == 1 && hours > 0)
   
                                                  // judge the hours of your working time
        if (hours > 40)
            hours = 40 + (hours - 40) * OVERTIME;
        else
            ;
        wage = hours * BASIC;

                                                 // judge the number of your salary
        if (wage > 450)
            tax += (wage - 450) * RATE_MORE_450 + 150 * RATE_MORE_300_LESS_450 + 300 * RATE_LESS_300;
        else if (wage > 300)
            tax += (wage - 300) * RATE_MORE_300_LESS_450 + 300 * RATE_LESS_300;
        else
            tax += wage * RATE_LESS_300;         //initialize BASIC wage for next computing
                                                 //print the answer
        printf("Your wage total is $%.2f, but you "
               "should pay tax $%.2f, so you could get $%.2f in the end.nnn",
               wage, tax, wage - tax);

        BASIC = basic_salary();
        if (BASIC == -1)
            return -1;
        printf("Please input your working hours(q to quit): ");
        tax = 0;                                 // initialize tax for next computing
    }
    printf("Done!n");

    return 0;
}

float basic_salary(void)
{
    float BASIC = 0;
    int choice = 0;
    printf("******************************************************************************************n");
    printf("Enter the number(1~4,5 and other to quit) corresponding to the desired pay rate or action:n");
    printf("1) %-5.2f/hr%20c2)$ %-5.2f/hrn", 8.75, ' ', 9.33);
    printf("3) %-5.2f/hr%20c4)$ %-5.2f/hrn", 10.00, ' ', 11.20);
    printf("5) quitn");
    printf("******************************************************************************************n");
    scanf("%d", &choice);
    switch (choice)
    {
    case 1:
        BASIC = 8.75;
        break;
    case 2:
        BASIC = 9.33;
        break;
    case 3:
        BASIC = 10.00;
        break;
    case 4:
        BASIC = 11.20;
        break;
    default:                                     //besides 1~4,quit
        printf("quit!n");
        return -1;                               // end the program
        break;
    }
    return BASIC;
}

运行示例:


Enter the number(1~4,5 and other to quit) corresponding to the desired pay rate or action:

  1. 8.75 /hr 2)$ 9.33 /hr
  2. 10.00/hr 4)$ 11.20/hr
  3. quit

4
Please input your working hours(q to quit): 55
Your wage total is $700.00, but you should pay tax $130.00, so you could get $570.00 in the end.


Enter the number(1~4,5 and other to quit) corresponding to the desired pay rate or action:

  1. 8.75 /hr 2)$ 9.33 /hr
  2. 10.00/hr 4)$ 11.20/hr
  3. quit

0
quit!

本程序是一个C语言练手项目
程序中最突出的地方是是判断何时退出程序以及
将基础工资选项这代码行数较多的部分封装成一个函数
通过返回值判断用户输入是否妥当,不妥当就退出程序

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/835825.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号