Hey everyone. I have a question. I am working on Visual Basic Express and I am supposed to calculate the change from a transaction.
Now what code would I use? I have it
Just did an Assignment like it. Public Class Form1 'Name: Aaron Holiday 'Class: IME 211 'Purpose: Change Calc
Dim Owed As Double
Dim Tend As Double
Dim Change As Double
Dim _20D As Integer
Dim _10D As Integer
Dim _5D As Integer
Dim _1D As Integer
Dim _25C As Integer
Dim _10C As Integer
Dim _5C As Integer
Dim _1C As Integer
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clear Due Amounts
txtOwed.Text = ""
txtTend.Text = ""
lblChange.Text = ""
'Clear Dollar Amounts
lbl20D.Text = ""
lbl10D.Text = ""
lbl5D.Text = ""
lbl1D.Text = ""
'Clear Cents Amounts
lbl25C.Text = ""
lbl10C.Text = ""
lbl5C.Text = ""
lbl1C.Text = ""
txtOwed.Focus()
End Sub
Private Sub btnRing_Click(sender As Object, e As EventArgs) Handles btnRing.Click
'Check to see if Empty
If ((txtOwed.Text) = Nothing) Then
lblChange.Text = ("Error")
MessageBox.Show("Please Enter Amount Owed")
Exit Sub
End If
If ((txtTend.Text) = Nothing) Then
lblChange.Text = ("Error")
MessageBox.Show("Please Enter Amount Tendered")
Exit Sub
End If
'Set Dim Values
Owed = txtOwed.Text
Tend = txtTend.Text
'Calculate Change due
Change = (Tend - Owed)
lblChange.Text = Change.ToString("C2")
'Check if they paid enough
If ((lblChange.Text) < 0) Then
lblChange.Text = ("Pay Up!")
MessageBox.Show("Please Pay full Amount!")
Exit Sub
End If
'Set Dim Values
_20D = 0 '$20
_10D = 0 '$10
_5D = 0 '$5
_1D = 0 '$1
_25C = 0 '$0.25
_10C = 0 '$0.10
_5C = 0 '$0.05
_1C = 0 '$0.01
'Find Amounts of Each
Do While Change >= 20
_20D = _20D + 1
Change = Change - 20
Loop
'Display $20s
lbl20D.Text = _20D
'================================================
Do While Change >= 10
_10D = _10D + 1
Change = Change - 10
Loop
'Display $10s
lbl10D.Text = _10D
'================================================
Do While Change >= 5
_5D = _5D + 1
Change = Change - 5
Loop
'Display $5s
lbl5D.Text = _5D
'================================================
Do While Change >= 1
_1D = _1D + 1
Change = Change - 1
Loop
'Display $1s
lbl1D.Text = _1D
'================================================
Do While Change >= 0.25
_25C = _25C + 1
Change = Change - 0.25
Loop
'Display $0.25s
lbl25C.Text = _25C
'================================================
Do While Change >= 0.1
_10C = _10C + 1
Change = Change - 0.1
Loop
'Display $0.10s
lbl10C.Text = _10C
'================================================
Do While Change >= 0.05
_5C = _5C + 1
Change = Change - 0.05
Loop
'Display $0.05s
lbl5C.Text = _5C
'================================================
Do While Change >= 0.01
_1C = _1C + 1
Change = Change - 0.01
Loop
'Display $0.01s
lbl1C.Text = _1C
'Display Thank you
If ((lblChange.Text) >= 0) Then
MessageBox.Show("Thank you, Come Again")
End If
End Sub
End Class