A
Amy
Newbie needs help with homework how can I return change in numbers or
dollars, quarters etc?
This question is so simple I am embarrassed to put it here but I have only
been coding for 1 month and am totally stumped!!
My homework requires me to make a program that calculates change returned
and then displays how many dollars, quarters, dimes, nickels, and pennies to
give back for the change. like $2.32 in change is 2 dollars 3 dimes and 2
pennies.
I don't know if I am stupid in math or coding or both but I can not make
this work. can someone help?
Private Sub CalculateChangeButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CalculateChangeButton.Click
'Declare variables
Dim decAmountOwed, decAmountPaid, decChangeOwed As Decimal
Dim sngDollarsOwed, sngQuartersOwed, sngDimesOwed, sngNicklesOwed,
sngPenniesOwed, _
sngChangeChange As Single
'Assign values to variables
decAmountOwed = Val(Me.AmountOwedTextBox.Text)
decAmountPaid = Val(Me.AmountPaidTextBox.Text)
sngDollarsOwed = Val(Me.DollarsOutputLabel.Text)
sngQuartersOwed = Val(Me.QuartersOutputlabel.Text)
sngDimesOwed = Val(Me.DimesOutputlabel.Text)
sngNicklesOwed = Val(Me.NicklesOutputLabel.Text)
sngPenniesOwed = Val(Me.PenniesOutputlabel.Text)
'Perform Calculations
'Calculate and display the change owed
decChangeOwed = decAmountPaid - decAmountOwed
Me.ChangeOwedOutputLabel.Text = Format(decChangeOwed, "currency")
'Calculate and display the dollars owed
sngDollarsOwed = Val(decChangeOwed) Mod 1
Me.DollarsOutputLabel.Text = sngDollarsOwed
'Calculate and display the number of Quarters owed
'Calculate and display the number of Dimes owed
'Calculate and display the number of Nickles owed
'Calculate and display the number of Pennies owed
'Display formatted results in the controls
Me.AmountOwedTextBox.Text = Format(decAmountOwed, "currency")
Me.AmountPaidTextBox.Text = Format(decAmountPaid, "currency")
'Send the focus to the Amount Owed box
Me.ClearScreenButton.Focus()
End Sub
End Class
dollars, quarters etc?
This question is so simple I am embarrassed to put it here but I have only
been coding for 1 month and am totally stumped!!
My homework requires me to make a program that calculates change returned
and then displays how many dollars, quarters, dimes, nickels, and pennies to
give back for the change. like $2.32 in change is 2 dollars 3 dimes and 2
pennies.
I don't know if I am stupid in math or coding or both but I can not make
this work. can someone help?
Private Sub CalculateChangeButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CalculateChangeButton.Click
'Declare variables
Dim decAmountOwed, decAmountPaid, decChangeOwed As Decimal
Dim sngDollarsOwed, sngQuartersOwed, sngDimesOwed, sngNicklesOwed,
sngPenniesOwed, _
sngChangeChange As Single
'Assign values to variables
decAmountOwed = Val(Me.AmountOwedTextBox.Text)
decAmountPaid = Val(Me.AmountPaidTextBox.Text)
sngDollarsOwed = Val(Me.DollarsOutputLabel.Text)
sngQuartersOwed = Val(Me.QuartersOutputlabel.Text)
sngDimesOwed = Val(Me.DimesOutputlabel.Text)
sngNicklesOwed = Val(Me.NicklesOutputLabel.Text)
sngPenniesOwed = Val(Me.PenniesOutputlabel.Text)
'Perform Calculations
'Calculate and display the change owed
decChangeOwed = decAmountPaid - decAmountOwed
Me.ChangeOwedOutputLabel.Text = Format(decChangeOwed, "currency")
'Calculate and display the dollars owed
sngDollarsOwed = Val(decChangeOwed) Mod 1
Me.DollarsOutputLabel.Text = sngDollarsOwed
'Calculate and display the number of Quarters owed
'Calculate and display the number of Dimes owed
'Calculate and display the number of Nickles owed
'Calculate and display the number of Pennies owed
'Display formatted results in the controls
Me.AmountOwedTextBox.Text = Format(decAmountOwed, "currency")
Me.AmountPaidTextBox.Text = Format(decAmountPaid, "currency")
'Send the focus to the Amount Owed box
Me.ClearScreenButton.Focus()
End Sub
End Class