Adding Overtime Pay

后端 未结 2 779
慢半拍i
慢半拍i 2021-01-28 08:14

the program works, but i\'m not sure how to get the grosspay to add the overtime pay once the if condition is set, I was told to set overtime pay to zero on the declaration. Is

2条回答
  •  悲&欢浪女
    2021-01-28 08:43

    This is one way to do it. You weren't ever actually setting the OvertimePay variable to equal anything other than 0. You should move the if condition up in the program logic and then set the variable accordingly before calculating gross pay (gp).

    #include
    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;
    
    
    
    }
    

提交回复
热议问题