-
My payroll calculator gives the wrong answer and i am pretty sure my code is right. It is supposed to give time and a half for hours worked over 40 but gives the wrong answer, it does give the right answer for hours under 40 though, here is the code: What's wrong? :(
Dim inthours As Integer
Dim intrate As Integer
Dim intgross As Integer
inthours = txthours.Text
intrate = txtrate.Text
If inthours > 40 Then
intrate = intrate * 1.5
lblgross.Caption = inthours * intrate
ElseIf inthours <= 40 Then
intrate = intrate
lblgross.Caption = inthours * intrate
End If
End Sub
-
This seems to work for me:
Code:
Private Sub Command1_Click()
Dim intHours As Integer
Dim intRate As Integer
Dim intGross As Integer
intHours = txthours.Text
intRate = txtrate.Text
If intHours > 40 Then
lblgross.Caption = 40 * intRate 'I added this line...
intRate = intRate * 1.5
lblgross.Caption = lblgross.Caption + (intHours - 40) * intRate '...and modified this one
ElseIf intHours <= 40 Then
intRate = intRate
lblgross.Caption = intHours * intRate
End If
End Sub
Also when you defined IntRate as Integer: it only works for even numbers, if your rate is odd, then 1.5 of it will always be .5 too much (hope you know what I mean - it simply rounds it)
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
[This message has been edited by QWERTY (edited 02-19-2000).]
-
Hi.
Worked hours = 60
Rate = 6
Hint, The way to do it:
(40 * 6) + (20 + 9) :)
QWERTY, Int gives the Integer part only. 1.5 => 1
Good Luck.
-
Thanks, I understand it now. And changed the rate one's to currency and did the other stuff. Thanks.
-
Actually Lyla 1.5 = 2 if you have variable defined as integer. Checked it, I can't be wrong. :)
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.