首页
学习
活动
专区
圈层
工具
发布

加班费
EN

Stack Overflow用户
提问于 2014-02-20 03:14:52
回答 2查看 161关注 0票数 0

该程序可以工作,但我不知道如何使grosspay添加加班费,一旦设置了条件,我就被告知在声明中将加班工资设置为零。一旦符合条件,是否有办法相应地改变加班费?例如,overtimepay= 50,所以毛薪的公式现在是hw*hp+ 50。

代码语言:javascript
复制
#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");

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-20 03:31:25

这是一种方法。实际上,您从未将OvertimePay变量设置为除0以外的任何值。您应该在程序逻辑中向上移动if条件,然后在计算总薪资(gp)之前相应地设置变量。

代码语言:javascript
复制
#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
EN

Stack Overflow用户

发布于 2014-02-20 03:20:12

你需要先计算加班费,然后再输出总工资:

代码语言:javascript
复制
if(hw > 40)
    OvertimePay = (hw - 40) * hp * 0.5;

gp = hw * hp + OvertimePay;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21897354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档