2017-03-25 25 views
0

我正在創建一個計算每週工資的計劃,其中加班工資是每週工資的1.5倍。 這是我的代碼:如何確定C調試錯誤中的每週薪酬;

#include <stdio.h> 

int main() 
{ 

    double payrate; 
    double hours; 
    double weeklypay = hours * payrate; 
    double overtimehours = hours - 40; 
    double overtimepay = weeklypay * 1.5; 
    double overtimesalary = weeklypay + (overtimehours * overtimepay); 

    printf("What is your standard hourly pay rate?\n"); 
    scanf("%d",&payrate); 
    printf("How many hours do you work in a week?\n"); 
    scanf("%d",&hours); 

    if (hours <= 40) 
    printf("This means your weekly pay is %d . \n", weeklypay); 

    else (hours > 40) 
    printf("This means your weekly pay is %d . \n", overtimesalary); 


    return 0; 
} 

我堅持跑步,我的程序時得到這個錯誤,我完全糊塗了,爲什麼?

expected ‘;’ before ‘printf’ 

我意識到我在做一些愚蠢的事情;如果有人能幫助我意識到我的錯誤,我會非常感激。

+2

你爲什麼與'emacs'這個標籤? – Dan

回答

2
if (hours <= 40) 
    printf("This means your weekly pay is %d . \n", weeklypay); 

    else (hours > 40) 
    printf("This means your weekly pay is %d . \n", overtimesalary); 

你錯過如果在else:

if (hours <= 40) 
    printf("This means your weekly pay is %d . \n", weeklypay); 

    else if (hours > 40) 
    printf("This means your weekly pay is %d . \n", overtimesalary); 

或在這種情況下,你可能只是將其刪除:

if (hours <= 40) 
    printf("This means your weekly pay is %d . \n", weeklypay); 

    else 
    printf("This means your weekly pay is %d . \n", overtimesalary);