Hey guys, I am new to vb and need some help with this change program. The idea is that we are given a certain amoun of change and then telling how many dollars, quarters, dimes, nickles and pennies. I thought I would convert the decimal to an integer and then use a while loop for every text box, i.e. dollars, quarters, dimes, etc.., to show how many of each, but the while loop is confusing for me in vb, but to tell you the truth I don't know if I am on the right track, can you help?

``````Public Class Form1

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim getChange As Decimal = txtStart.Text
Dim intGetChange As Integer = Convert.ToInt32(getChange)

While intGetChange > 100
intGetChange(-100)

End While

Dim showDollars As Integer = intGetChange
Dim showQuarters As Integer = txtQuarters.Text
Dim showDimes As Integer = txtDimes.Text
Dim showNickles As Integer = txtNickles.Text
Dim showPennies As Integer = txtPennies.Text

End Sub
End Class``````
2
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by Geekitygeek

What you need to do is use mod division and integer division in a loop to calculate the number of each denimination in the total. Here's a rough pseudocode to get you started:

for each denomination (largest to smallest)
number of denomination = remainder \ denomination (this is integer division)
remainder = remainder MOD denomination
loop

99\50 = 1
99 MOD 50 = 49

49\20 = 2
49 MOD 20 = 9

ETC

I understand the division and then mod part but when I try to divide the variable by 100 it gives me an error that it is not a method, also once I get the loop to work how do I get dollars to display to the appropriate text box.

``````Public Class Form1

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim getChange As Decimal = txtStart.Text
Dim intGetChange As Integer = Convert.ToInt32(getChange)
Dim showDollars As Integer = txtDollars.Text
Dim showQuarters As Integer = txtQuarters.Text
Dim showDimes As Integer = txtDimes.Text
Dim showNickles As Integer = txtNickles.Text
Dim showPennies As Integer = txtPennies.Text

For intGetChange = 999999 To 100

intGetChange \ 100

Next

End Sub
End Class``````

Edited by songweaver: n/a

I looked a C++ problem, and I created something similar, however I can't seem to attach the text boxes it is giving me an error, can you help?

``````Public Class Form1
Dim remainder As Integer
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim getChange As Decimal = txtStart.Text
Dim intGetChange As Integer = Convert.ToInt32(getChange)
Dim showDollars As Integer = txtDollars.Text
Dim showQuarters As Integer = txtQuarters.Text
Dim showDimes As Integer = txtDimes.Text
Dim showNickles As Integer = txtNickles.Text
Dim showPennies As Integer = txtPennies.Text

If intGetChange > 100 Then
showDollars = intGetChange / 100
remainder = intGetChange Mod 100
showQuarters = intGetChange / 25
remainder = intGetChange Mod 25
showDimes = intGetChange / 10
remainder = intGetChange Mod 10
showNickles = intGetChange / 5
remainder = intGetChange Mod 5
showPennies = intGetChange

End If

End Sub
End Class``````

You need to use remainder instead of intGetChange after you calculate Dollars:

``````showQuarters = remainder / 25
remainder = remainder Mod 25``````

You're using the textboxes incorrectly:

``Dim showDollars As Integer = txtDollars.Text``

this is attempting to store the text value in txtDollars into your showDollars variable. It is failing because you are implicitly casting the string to an integer.

You need to just declare the Integers first `Dim showDollars As Integer` , then set their values `showDollars = intGetChange / 100` , THEN show that value in the textbox `txtDollars.Text = showDollars` at the end.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.