1. 程式人生 > >程式設計C 實驗二 題目一 計算員工周工資(0077)

程式設計C 實驗二 題目一 計算員工周工資(0077)

編寫一個程式,輸入某僱員的每週工作時間(以小時計)和每小時的工資數,計算並輸出他的工資。(如果時間小於0或大於一週的總時間輸出input is wrong!)若僱員周工作小時超過40 小時,則超過部分按原工資的1.5 倍的加班工資來計算, 若僱員每週工作小時超過60 小時,則超過60 的部分按原工資的倍的加班工資來計算, 40 60 小時的工資仍按照原工資的1.5 倍的加班工資來計算。

Description

輸入工作時間和每小時的工資(只輸入一組測試資料)

Input

總的薪金

Output
1 2 3 4 5 30 4 45 4.5 60 5 -10 4
Sample Input
1 2 3 4 120 213.75 350 input is wrong!
Sample Output

Toshio友情提示:
當你不清楚小數點後是否保有有效資料的時候,你可以用%g輸出如printf("%g\n",answer);
如answer為12.50自動輸出12.5,若answer為12.00自動輸出12


若僱員周工作小時超過40 小時,則超過部分按原工資的1.5 倍的加班工資來計算, 若僱員每週工作小時超過60 小時,則超過60 的部分按原工資的3 倍的加班工資來計算, 而40 到60 小時的工資仍按照原工資的1.5 倍的加班工資來計算。


#include <stdio.h>
 
int main() {
    int time;
    float salary,total;
    scanf("%d %g",&time,&salary);
    if(time < 0 || time > 168) {
        printf("input is wrong!\n");
        return 0;
    } else if (time >= 40) {
        total = 40 * salary + (time - 40) * 1.5 * salary;
    } else if (time >= 60) {
        total = 40 * salary + 20 * 1.5 * salary + (time - 60) * 3 * salary;
    } else if (time > 0 && time < 40) {
        total = time * salary;
    }
    printf("%g\n",total);
    return 0;
}