我的CalcPay方法没有正确计算加班时间,任何人都可以看到任何会引起这种问题的明显问题吗?
private const double FED_TAX = 0.2;
private const int FULL_TIME = 40;
private const double OVER_TIME = 1.5;
private const double STATE_TAX = 0.075;
public double CalcPay()
{
double pay = hoursWorked * hourlyWage;
double overTimeHors = hoursWorked - FULL_TIME;
if (overTimeHours > 0)
{
pay = overTimeHors * (hourlyWage * OVER_TIME);
}
double tax1 = pay * FED_TAX;
double tax2 = pay * STATE_TAX;
return ((pay - tax1) - tax2);
}
答案 0 :(得分:2)
您需要将加班费添加到主要工资中,而不是替换它:
if (overTime > 0)
{
pay += overTime * (hourlyWage * OVER_TIME);
// ^ increment
}
答案 1 :(得分:1)
问题在于您重新定义了变量薪酬,这意味着您的计算基于加班费率......