ETH官方钱包

切換
舊版
前往
大廳
主題

C語言:薪資計算工具

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


#include <stdio.h>

int main()
{
    int hours;          //工作時數
    float hourlyRate;   //每小時工資
    float salary;       //應得工資

    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);

        //超過40小時以正常工資的1.5倍計算
        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;
}

創作回應

亨利王子
請問 已知工時跟時薪要如何寫?
2022-05-11 20:01:11

更多創作