1

我坚持如何修改它,以便为超过 40 小时的任何工作时间支付员工时间和一半。我知道这将是一个 if 语句,但我不确定我将如何具体处理它.

示例:如果用户输入 35.5 小时和 9.56 作为费率,则净值为 237.56 美元。

输入:工作时间和工资率。

输出:不同的税收和净工资。

这是我到目前为止所拥有的:

    Const FWT_ As Decimal = 0.2
    Const FICA_ As Decimal = 0.08
    Const STAT As Decimal = 0.02

    Dim Hrs As Decimal
    Dim Rate As Decimal
    Dim Gros As Decimal
    Dim FWT As Decimal
    Dim Fi As Decimal
    Dim stat As Decimal
    Dim NetPay As Decimal


    Decimal.TryParse(txtHours.Text, Hrs)
    Decimal.TryParse(txtRate.Text, Rate)


    Gros = Math.Round(Hrs * Rate, 2)
    FWT = Math.Round(Gros * FWT_, 2)
    Fi = Math.Round(Gros * FICA_, 2)
    stat = Math.Round(Gros * STAT, 2)
    NetPay = Gros - FWT - Fi - stat

    lblGr.Text = Gros.ToString("N2")
    lblF.Text = Fi.ToString("N2")
    lblF.Text = Fi.ToString("N2")
    lblSt.Text = stat.ToString("N2")
    lblN.Text = NetPay.ToString("C2")

谢谢你。

4

2 回答 2

1

You could just add 0.5 * Rate pay for any hours worked over 40 to your existing calculation:

If Hrs > 40 Then
    Gros += Math.Round( (Hrs-40) * Rate * 0.5 )
End If
于 2012-09-11T21:16:10.590 回答
1

I don't know how specifically to write the answer such that it will compile in your visual basic program but i can give you the algorithmic answer

if(hours > 40)
    payment = 40 * rate + ((hours-40)) * (rate*1.5);
else
    payment = hours * rate;

or if VB supports the ternary operator

payment = hours > 40 ? (40 * rate + ((hours-40)) * (rate*1.5)) : (hours * rate);

If i were to be given this code to edit the first thing i'd try is :

Gros = Math.Round(Hrs * Rate, 2)

to

Gros = Math.Round(hours > 40 ? (40 * rate + ((hours-40)) * (rate*1.5)) : (hours * rate), 2)
于 2012-09-11T21:17:06.010 回答