2014-02-20 64 views
0

該計劃有效,但我不知道如果一旦條件設定後如何讓毛支付加上加班工資,我被告知在申報時將加班工資設置爲零。一旦滿足條件,是否有辦法相應地改變加班工資?例如 overtimepay = 50 所以工資總額的公式現在將是漢王* HP + 50添加加班費

#include<iostream> 
using namespace std; 
int main() 

{ 
    float ftax, stax, SDI, SS, hw, hp, pay, netpay, gp, OvertimePay = 0; 

    cout << "please enter the hoursWorked: "; 
    cin >> hw; 

    cout << "---------------------" << endl; 
    cout << "please enter the hourlyPay: "; 
    cin >> hp; 

    gp = hw * hp + (OvertimePay); 
    ftax = gp*.10; 
    stax = gp*.08; 
    SDI = gp*.01; 
    SS = gp*.06; 
    netpay = gp - (ftax + stax + SDI + SS); 

    cout << " grosspay = " << gp << endl; 
    cout << "---------------------" << endl; 
    cout << " federal taxes = " << ftax << endl; 
    cout << "---------------------" << endl; 
    cout << " state taxes = " << stax << endl; 
    cout << "---------------------" << endl; 
    cout << " SDI = " << SDI << endl; 
    cout << "---------------------" << endl; 
    cout << " Social Securities = " << SS << endl; 
    cout << "---------------------" << endl; 
    cout << " netpay = " << netpay << endl; 
    cout << "---------------------" << endl; 

    if(hw > 40) 

     cout << "OvertimePay = " << (hw - 40) * hp * 0.5 << endl; 

    system("pause"); 

} 
+1

我建議你離開代碼一分鐘,用鉛筆和紙製作一個例子。 –

+0

無關:在我最瘋狂的夢想中,我的聯邦稅收負擔是10%。這是24%*短*。而FICA是[7.65%](http://www.ssa.gov/pressoffice/factsheets/colafacts2014.html)(x2但你的老闆得付另一半)。你的老師需要更新他們的材料= P – WhozCraig

回答

0

這是做到這一點的一種方法。您實際上沒有將OvertimePay變量設置爲等於0以外的任何值。您應該將if條件向上移動到程序邏輯中,然後在計算毛支付(gp)之前相應地設置變量。

#include<iostream> 
using namespace std; 
int main() 

{ 
float ftax, stax, SDI, SS, hw, hp, pay, netpay, gp, OvertimePay = 0; 

cout << "please enter the hoursWorked: "; 
cin >> hw; 

cout << "---------------------" << endl; 
cout << "please enter the hourlyPay: "; 
cin >> hp; 

if(hw > 40) { 
    OvertimePay = (hw - 40) * hp * .5; 
} else { 
    OvertimePay = 0; 
} 


gp = (hw * hp) + OvertimePay; 
ftax = gp*.10; 
stax = gp*.08; 
SDI = gp*.01; 
SS = gp*.06; 
netpay = gp - (ftax + stax + SDI + SS); 

cout << " grosspay = " << gp << endl; 
cout << "---------------------" << endl; 
cout << " federal taxes = " << ftax << endl; 
cout << "---------------------" << endl; 
cout << " state taxes = " << stax << endl; 
cout << "---------------------" << endl; 
cout << " SDI = " << SDI << endl; 
cout << "---------------------" << endl; 
cout << " Social Securities = " << SS << endl; 
cout << "---------------------" << endl; 
cout << " netpay = " << netpay << endl; 
cout << "---------------------" << endl; 



} 
+0

謝謝安德魯L,工作 – user3330862

+0

'else'是多餘的,因爲'OvertimePay'變量在聲明中初始化,所以'} else {OvertimePay = 0; ''可以被刪除。 –

0

你需要計算加班先支付,輸出工資總額之前:

if(hw > 40) 
    OvertimePay = (hw - 40) * hp * 0.5; 

gp = hw * hp + OvertimePay; 
+0

我已經有加班工資了,但是我希望它能夠代替上面的毛工資公式,所以它把總工資數字吐出來,包括加班費,然後完成所有的稅收,到目前爲止我的計劃只給了我沒有加班的總收入 – user3330862

+0

明白了。錯誤的問題。看我的編輯。 –

+0

感謝您的幫助 – user3330862