程序显示错误的值,需要更改什么?

时间:2013-12-02 21:53:44

标签: vb.net visual-studio-2013

我的显示员工记录的程序除了在付款时显示不正确的值以外,还可以正常工作。需要改变什么?

Sub AddPlist(month As String, age As String, employeenumberid As Integer, hourlyrateline As Integer)

        Dim hoursworkedline As String
        Dim normalhoursworked As Integer
        Dim overtimerate As String
        Dim normalpay As Decimal
        Dim overtimepay As Decimal
        Dim overtimehoursworked As Integer
        Dim grosspay As Decimal
        Dim taxrate As Decimal
        Dim taxdeducted As Decimal
        Dim nideducted As Decimal
        Dim netpay As Decimal

        Do
            Console.Write("Please enter hoursworked: ")
            hoursworkedline = Console.ReadLine()
            If Not hoursworkedline IsNot Nothing OrElse Not IsNumeric(hoursworkedline) Then Console.Write("hoursworked must be entered!!: ")
        Loop While Not hoursworkedline IsNot Nothing OrElse Not IsNumeric(hoursworkedline)

        If hoursworkedline > 40 Then
            normalhoursworked = 40
            overtimerate = hourlyrateline * 0.15
            overtimehoursworked = hoursworkedline - 40
            normalpay = normalhoursworked * hourlyrateline
            overtimepay = overtimehoursworked * overtimerate
            grosspay = normalpay + overtimepay
            taxrate = If(age < 18, 18, If(age < 60, 25, If(age > 60, 20, Nothing)))
            taxdeducted = grosspay * taxrate
            nideducted = grosspay * ((grosspay / 100) * 7)
            netpay = grosspay - taxdeducted - nideducted
        Else
            normalhoursworked = hoursworkedline
            overtimerate = hourlyrateline * 0.15
            overtimehoursworked = 0
            normalpay = normalhoursworked * hourlyrateline
            overtimepay = 0
            grosspay = normalpay + overtimepay
            taxrate = If(age < 18, 18, If(age < 60, 25, If(age > 60, 20, Nothing)))
            taxdeducted = grosspay * taxrate
            nideducted = grosspay * ((grosspay / 100) * 7)
            netpay = grosspay - taxdeducted - nideducted
        End If

1 个答案:

答案 0 :(得分:0)

我发现错误的一件事是你只支付加班费的15%的小时费率。我想你的意思是乘以1.5而不是.15

另外,你的代码中有很多重复,请考虑这一点:

If hoursworkedline > 40 Then
    normalhoursworked = 40
    overtimehoursworked = hoursworkedline - 40
Else
    normalhoursworked = hoursworkedline
    overtimehoursworked = 0
End If
    overtimerate = hourlyrateline * 1.5
    normalpay = normalhoursworked * hourlyrateline
    overtimepay = overtimehoursworked * overtimerate
    grosspay = normalpay + overtimepay
 'Also your taxrate algorithm doesn't allow for someone exactly 60
    taxrate = If(age < 18, 18, If(age < 60, 25, If(age >= 60, 20, Nothing)))
 'Another thing your multiplying the grosspay by whole numbers not percentages
    taxdeducted = grosspay * (taxrate / 100)
 'Not sure what outcome you expect from this but it doesn't look quite right
    nideducted = grosspay * ((grosspay / 100) * 7)
    netpay = grosspay - taxdeducted - nideducted