c how to program 习题3.20

发布于2020-05-03 1,039 热度

运行结果:

C语言代码:

/* c how to program 习题3.20 */
#include <stdio.h>
#include <stdlib.h>

int main()
{
    //分别定义变量
    double houers, rate, salary;

    //获取第一个员工的工作时间
    printf("Enter number of hours worked (-1 to end): ");
    scanf("%lf", &houers);

    //进入循环,直到输入-1结束
    while (houers != -1.0){
        //获取员工每小时的工资
        printf("Enter hourly rate of the worker ($00.00): ");
        scanf("%lf", &rate);

        //计算并打印员工的工资
        if(houers > 40.0){
            salary = 40.0 * rate + ( houers - 40.0 ) * rate * 1.5;
        }
        else{
            salary = houers * rate;
        }
        printf("Salary is $%.2lf\n\n", salary);


        //获取下一个员工的工作时间
        printf("Enter number of hours worked (-1 to end): ");
        scanf("%lf", &houers);
    }

    return 0;

}

记录工作,记录学习,分享知识,分享经验……