Hello everyone.
I have a program that is driving me crazy. It is a cashier change return where the user enter the amount owed and the amount paid and when he/she press calculate the program should display the change due as well as the number of Dollars, Quarters, Dimes, Nickels, and pennies returned to the customer. When I run the program sometimes it gives me the right output and others it gives wrong output and it rounds the output. I just want to let you know that I have the option strict on. I will paste the code below please help me ASAP!!!!!!
Thanks in advance
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' close the application
Me.Close()
End Sub
Private Sub btnClr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClr.Click
' clear all the labels and textboxes and prepare the screen for the next entry
txtOwed.Text = ""
txtPaid.Text = ""
lblChangDue.Text = ""
lblDollars.Text = ""
lblQuart.Text = ""
lblDimes.Text = ""
lblNickels.Text = ""
lblPenn.Text = ""
' send the focus to the Amount owed text box
txtOwed.Focus()
End Sub
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click
' declare named constants
Const intDOLLARS_VALUE As Integer = 1
Const decQUART_VALUE As Decimal = 0.25D
Const decDIMES_VALUE As Decimal = 0.1D
Const decNICKELS_VALUE As Decimal = 0.05D
Const decPENN_VALUE As Decimal = 0.01D
'declare variables
Dim decOwed As Decimal
Dim decPaid As Decimal
Dim decChange As Decimal
Dim intDollars As Integer
Dim decRemaining As Decimal
Dim intQuart As Integer
Dim decRemainingTwo As Decimal
Dim intDimes As Integer
Dim decRemainingThree As Decimal
Dim intNickels As Integer
Dim decRemainingFour As Decimal
Dim intPenn As Integer
' calculate the change due
Decimal.TryParse(txtOwed.Text, decOwed)
Decimal.TryParse(txtPaid.Text, decPaid)
decChange = decPaid - decOwed
' claculate the dollars
intDollars = Convert.ToInt32((decChange / intDOLLARS_VALUE) - (decChange Mod intDOLLARS_VALUE))
decRemaining = decChange - (intDollars * intDOLLARS_VALUE)
' calculates the quarters
intQuart = Convert.ToInt32((decRemaining / decQUART_VALUE) - (decRemaining Mod decQUART_VALUE))
decRemainingTwo = decRemaining - (intQuart * decQUART_VALUE)
' calculate the dimes
intDimes = Convert.ToInt32((decRemainingTwo / decDIMES_VALUE) - (decRemainingTwo Mod decDIMES_VALUE))
decRemainingThree = decRemainingTwo - (intDimes * decDIMES_VALUE)
' calculate the nickels
intNickels = Convert.ToInt32((decRemainingThree / decNICKELS_VALUE) - (decRemainingThree Mod decNICKELS_VALUE))
decRemainingFour = decRemainingThree - (intNickels * decNICKELS_VALUE)
' calculate the pennies
intPenn = Convert.ToInt32((decRemainingFour / decPENN_VALUE) - (decRemainingFour Mod decPENN_VALUE))
lblChangDue.Text = decChange.ToString("C2")
lblDollars.Text = Convert.ToString(intDollars)
lblQuart.Text = Convert.ToString(intQuart)
lblDimes.Text = Convert.ToString(intDimes)
lblNickels.Text = Convert.ToString(intNickels)
lblPenn.Text = Convert.ToString(intPenn)
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' gets the username
' declare a variable
Dim strUserName As String
Const strPrompt As String = "Enter username:"
Const strTITLE As String = "Username Entery"
' assign the username to the variable
strUserName = InputBox(strPrompt, strTITLE)
' puts the username beside the Change Calculator
Me.Text = Me.Text & " " & strUserName
End Sub
Private Sub CLEARLABELS(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles txtOwed.TextChanged, txtPaid.TextChanged
' clears all labels when amount owed or amount paid is changed
lblChangDue.Text = ""
lblDollars.Text = ""
lblQuart.Text = ""
lblDimes.Text = ""
lblNickels.Text = ""
lblPenn.Text = ""
End Sub
End Class