Help with program

FrAncIs

New member
Joined
Sep 27, 2005
Messages
2
Programming Experience
Beginner
Im a beginner in programming, and im trying to create a program that calculates amount of money owed and paid, then show how many dollars, quarters, dimes, nickels and dimes to give back, example:$1.25 would be 1 dollar 1 quarter, this is my code so far, up until the quarters code it works good...




Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click

'Declare variables

Dim amountowed, amountpayed, change As Double

Dim dollars, quarters, dimes, nickels, pennies As Double

'Assign value to variables

amountowed = Double.Parse(Me.AOTextBox.Text)

amountpayed =
Double.Parse(Me.APTextbox.Text)

'Calculate change

change = amountpayed - amountowed

Me.TotalTextbox.Text = Convert.ToString(change)

Me.TotalTextbox.Text = Format(change, "currency")

'Display Dollars

dollars = Math.Floor(change)

Me.Dolllabel.Text = Convert.ToString(dollars)

'Display quarters

quarters = (change - dollars) / 0.25

quarters = Math.Floor(quarters)

Me.qrtlabel.Text = Convert.ToString(quarters)

'Display dimes

dimes = (change - (dollars + quarters * 0.25)) / 0.1

dimes = Math.Round(dimes)

Me.dimelabel.Text = Convert.ToString(dimes)

'Display nickels

nickels = (change - (dollars + (quarters * 0.25) + (dimes * 0.1))) / 0.05

nickels = Math.Round(nickels)

Me.nickelabel.Text = Convert.ToString(nickels)

'Display pennies





End Sub

i also thought about using integers but i have no idea because the code editor always give me error
 
I'm not sure how you solved this but you should have been using the "\" (integer division) and Mod operators. Also, you should definitely be using Integer variables. If you are getting errors then deal with the errors rather than taking the easy road and using an inappropriate data type.
 
Back
Top