ETH官方钱包

切換
舊版
前往
大廳
主題

C語(yǔ)言:薪資計(jì)算工具

查理 | 2013-09-10 09:25:00 | 巴幣 0 | 人氣 1269


#include <stdio.h>

int main()
{
    int hours;          //工作時(shí)數(shù)
    float hourlyRate;   //每小時(shí)工資
    float salary;       //應(yīng)得工資

    printf("Enter # of hours worked (-1 to end): ");
    scanf("%d", &hours);

    while(hours !=-1){
        printf("Enter hourly rate of the worker ($00.00): ");
        scanf("%f",&hourlyRate);

        //超過(guò)40小時(shí)以正常工資的1.5倍計(jì)算
        if(hours>40){
            salary=(float)hours*hourlyRate*1.5;
        }
        else{
            salary=(float)hours*hourlyRate;
        }

        printf("Salary is $%.2f\n\n",salary);

        printf("Enter # of hours worked (-1 to end):");
        scanf("%d", &hours);
    }
    system("pause");
    return 0;
}

創(chuàng)作回應(yīng)

亨利王子
請(qǐng)問(wèn) 已知工時(shí)跟時(shí)薪要如何寫(xiě)?
2022-05-11 20:01:11

更多創(chuàng)作