Hi I am new to this forum. I missed some class last week due to my wife and baby being sick. I turned in a wage calculator project and my instructor said I got the math for calculating the overtime right, but its not calculating the tax for the overtime. I have looked everywhere in my book and I cant for the life of mee see what I am missing
Thread moved from the 'Chit-chat' forum (for non-technical chat) to the 'VB.Net' (VB2002 and later) forum
To make it easier for people to help, here is the contents of the attached file:
Code:
' Program Name: Payroll Calculator
' Author: Chad Hakala
' Date: 12/5/2017
' Purpose: Calculates and displays payroll information
Public Class frmPayRollCalculator
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
' Declarations
Dim decEnterHours As Decimal
Dim decEnterPay As Decimal
Dim decGross As Decimal
Dim decTax As Decimal
Dim decSingle As Decimal = 0.19
Dim decFamily As Decimal = 0.16
' This line text the textboxs to see if they are numeric
If IsNumeric(txtEnterPay.Text) And IsNumeric(txtEnterHours.Text) Then
decEnterHours = Convert.ToDecimal(txtEnterHours.Text)
decEnterPay = Convert.ToDecimal(txtEnterPay.Text)
' this line calculates the users gross pay, net pay and taxes.
' Displays a msg box if the values entered are not rigth.
If decEnterPay <= 40.0 And decEnterPay >= 8.0 Then
If decEnterHours >= 5 And decEnterHours <= 60 Then
If decEnterHours <= 40 Then
If radSingle.Checked Then
decGross = decEnterHours * decEnterPay
decTax = decGross * decSingle
ElseIf radFamily.Checked Then
decGross = decEnterHours * decEnterPay
decTax = decGross * decFamily
End If
End If
If decEnterHours > 40 Then
If radSingle.Checked Then
decGross = 40 * decEnterHours
decTax = decGross * decSingle
ElseIf radFamily.Checked Then
decGross = 40 * decEnterPay
decTax = decGross * decFamily
End If
decGross += (decEnterHours - 40) * (decEnterPay * 1.5)
End If
Else
MsgBox("Hours must be greater than 5 or less than 60 ")
radFamily.Checked = False
radSingle.Checked = False
lblDisplayGross.Text = ""
lblDisplayNet.Text = ""
lblDisplayName.Text = ""
txtEnterHours.Clear()
txtEnterPay.Clear()
txtEnterName.Clear()
txtEnterName.Focus()
End If
Else
MsgBox("pay must be under 40 and above 8")
radFamily.Checked = False
radSingle.Checked = False
lblDisplayGross.Text = ""
lblDisplayNet.Text = ""
lblDisplayName.Text = ""
txtEnterHours.Clear()
txtEnterPay.Clear()
txtEnterName.Clear()
txtEnterName.Focus()
End If
Else
MsgBox("Please Enter a numeric value ")
radFamily.Checked = False
radSingle.Checked = False
lblDisplayGross.Text = ""
lblDisplayNet.Text = ""
lblDisplayName.Text = ""
txtEnterHours.Clear()
txtEnterPay.Clear()
txtEnterName.Clear()
txtEnterName.Focus()
End If
lblDisplayGross.Text = decGross.ToString("C")
lblDisplayTax.Text = decTax.ToString("C")
lblDisplayNet.Text = (decGross - decTax).ToString("C")
lblDisplayName.Text = txtEnterName.Text
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
' Clears the program
txtEnterName.Clear()
txtEnterHours.Clear()
txtEnterPay.Clear()
lblDisplayGross.Text = ""
lblDisplayNet.Text = ""
lblDisplayName.Text = ""
lblDisplayTax.Text = ""
txtEnterName.Focus()
radSingle.Focus()
End Sub
End Class
Hi I am new to this forum. I missed some class last week due to my wife and baby being sick. I turned in a wage calculator project and my instructor said I got the math for calculating the overtime right, but its not calculating the tax for the overtime. I have looked everywhere in my book and I cant for the life of mee see what I am missing
Code:
If decEnterHours > 40 Then
If radSingle.Checked Then
decGross = 40 * decEnterHours
decTax = decGross * decSingle
ElseIf radFamily.Checked Then
decGross = 40 * decEnterPay
decTax = decGross * decFamily
End If
decGross += (decEnterHours - 40) * (decEnterPay * 1.5)
End If
At first glance, I'm pretty sure the problem is you are calculating the final Overtime Gross pay after you've calculated the Tax. I believe you just need to move the bolded statement above the "If radSingle.Checked..." line.
Edit: You'll need to make more changes than just moving that line, you'll need to change it so that in that one line the Gross Pay is fully calculated, and then inside the radFamily/radSingle if statements there should be no recalculations of gross pay.
Last edited by OptionBase1; Dec 17th, 2017 at 05:09 PM.