I am having a problem. Im trying to write a simple code for a class project. The code is suppose to convert x number of pennies in a jar into dollars quarters nickles dimes and pennies. so using the example number 2399, that would be 23 dollars 3 quarters 2 dimes and 4 pennies.
Private Sub xCalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
'Converts the total number of pennies into dollars, quarters, dimes, nickels, and pennies
Dim Dollars As Integer
Dim Quarters As Integer
Dim Dimes As Integer
Dim Nickels As Integer
Dim Pennies As Integer
Dim QuarterChange As Integer
Dim DimeChange As Integer
Dim NickelChange As Integer
Dim PenniesChange As Integer
'Divides the number of pennies by 100
Dollars = Val(Me.xPenniesNum.Text) / 100
Me.xDollarLable.Text = Dollars
QuarterChange = Me.xPenniesNum.Text - (Dollars * 100)
Quarters = QuarterChange / 25
Me.xQuartersLable.Text = Quarters
DimeChange = Me.xPenniesNum.Text - (Dollars * 100) - (Quarters)
Dimes = DimeChange / 10
Me.xDimeLable.Text = Dimes
NickelChange = Me.xPenniesNum.Text - (Dollars * 100) - (Quarters) - (Dimes)
Nickels = NickelChange / 5
Me.xNickelLabe.Text = Nickels
PenniesChange = Me.xPenniesNum.Text - (Dollars * 100) - (Quarters) - (Dimes) - (Nickels)
Pennies = PenniesChange / 1
Me.xPenniesLabel.Text = Pennies
End Sub
that is the code i came up with but it doesnt work. I know why it doesnt work and that is when you divide the number by 100 it rounds up to 24 dollars. I just cant figure out how to fix this. Can someone give me a reference or something where i can find out how to write this?
Tags: