Hi
I have attempted this code for an application that calculates and displays change in terms of quarters, dimes, nickels and pennies. The user inserts the amount paid and the cost of the item both expressed in cents in two textboxes. Then I have four labels displaying the results for each kind of coin. This is the process for the button I named Calculate:
The results are wrong whenever I try to type some numbers. I can't figure out where I'm going wrong... I need to finish this tonight. If someone can help me out, I'd be very grateful. I don't know how to correct the code... I'm not really good at programming, just starting
.
I have attempted this code for an application that calculates and displays change in terms of quarters, dimes, nickels and pennies. The user inserts the amount paid and the cost of the item both expressed in cents in two textboxes. Then I have four labels displaying the results for each kind of coin. This is the process for the button I named Calculate:
VB.NET:
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
' Variables for fields
Dim lblCost As Double = CDbl(txtCostItm.Text)
Dim lblAmnt As Double = CDbl(txtAmntGvn.Text)
' Find Difference between Cost of Item and Price Received
Dim temp As Double = txtAmntGvn.Text - txtCostItm.Text
'Declare Integers
Dim lblQuar As Integer
Dim lblDim As Integer
Dim lblNick As Integer
Dim lblPenn As Integer
'How many quarters will be handed
lblQuar = CInt(temp / 25)
temp = temp - CDbl(CDbl(lblQuar) * 25)
lblQrts.Text = lblQuar.ToString
'Dimes
lblDim = CInt(temp / 10)
temp = temp - CDbl(CDbl(lblDim) * 10)
lblDimes.Text = lblDim.ToString
'Nickels
lblNick = CInt(temp / 5)
temp = temp - CDbl(CDbl(lblNick) * 5)
lblNckls.Text = lblNick.ToString
'Pennies
lblPenn = CInt(temp / 1)
temp = temp - CDbl(CDbl(lblPenn) * 1)
lblPennies.Text = lblPenn.ToString
The results are wrong whenever I try to type some numbers. I can't figure out where I'm going wrong... I need to finish this tonight. If someone can help me out, I'd be very grateful. I don't know how to correct the code... I'm not really good at programming, just starting