# Change Maker

Page 1 of 1

## 3 Replies - 5128 Views - Last Post: 23 April 2007 - 08:15 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=27098&amp;s=e718724ca25296f7a411c8ac9f132bc0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 TheNewGuy

Reputation: 0
• Posts: 4
• Joined: 23-April 07

# Change Maker

Posted 23 April 2007 - 08:05 PM

Hi, I'm starting this adult ed programming class. Our assignment is to create a coin change maker. I know weird name.

I've got the basic's down. I think

Here's what I've coded so far.

``` Dim TotalAmount As Decimal
Dim half As Decimal
Dim quarter As Decimal
Dim dime As Decimal
Dim nickel As Decimal
Dim penny As Decimal

TotalAmount = Val(Me.txtTotalAmount.Text)
'TotalAmount = TotalAmount * 100

If Me.chk50.Checked Then
half = TotalAmount / 0.5
TotalAmount = TotalAmount / 0.5
Me.txt50.Text = CStr(CInt(half))

End If
If Me.chk25.Checked Then
quarter = TotalAmount / 0.25
TotalAmount = TotalAmount / 0.25
Me.txt25.Text = CStr(CInt(quarter))

End If
If Me.chk10.Checked Then
dime = TotalAmount / 0.1
TotalAmount = TotalAmount / 0.1
Me.txt10.Text = CStr(CInt(dime))

End If
If Me.chk5.Checked Then
nickel = TotalAmount / 0.05
TotalAmount = TotalAmount / 0.05
Me.txt5.Text = CStr(CInt(nickel))

End If
If Me.chk1.Checked Then
penny = TotalAmount / 0.01
TotalAmount = TotalAmount / 0.01
Me.txt1.Text = CStr(CInt(TotalAmount))

End If
```

Here's what my gui looks like:

Is This A Good Question/Topic? 0

## Replies To: Change Maker

### #2 Goddard

Reputation: 1
• Posts: 25
• Joined: 23-April 07

## Re: Change Maker

Posted 23 April 2007 - 08:10 PM

I recently had to do something like this in my visual basic class. The trick is to use Modulus Arithmetic (Mod) It's like dividing but the answer is only a remainder. So 11 divided by 5 is 2.2 But, 11 mod 5 is the remainder of .2

Your close, you have the right set-up. You also want the pennies to always be checked in case it's not an even amount your getting change for.

```Dim sngInput As Single
Dim intcount As Integer

'clear out all old values
txt50.Text = ""
txt25.Text = ""
txt10.Text = ""
txt05.Text = ""
txt01.Text = ""

'assign the value in the text box to sngInput
Single.TryParse(Me.txtTotalAmount.Text, sngInput)

'Change it to pennies
sngInput = sngInput * 100

'as long as it's not zero
If sngInput <> 0 Then
If chk50.Checked Then
'\ gives you the whole number
' and mod gives you the remainder
intcount = sngInput \ 50
sngInput = sngInput Mod 50
'put in on the interface
txt50.Text = intcount
'reset the counter for the next coin value
intcount = 0
End If
If chk25.Checked Then
'\ gives you the whole number
' and mod gives you the remainder
intcount = sngInput \ 25
sngInput = sngInput Mod 25
'put in on the interface
txt25.Text = intcount
'reset the counter for the next coin value
intcount = 0
End If
If chk10.Checked Then
'\ gives you the whole number
' and mod gives you the remainder
intcount = sngInput \ 10
sngInput = sngInput Mod 10
'put in on the interface
txt10.Text = intcount
'reset the counter for the next coin value
intcount = 0
End If
If chk05.Checked Then
'\ gives you the whole number
' and mod gives you the remainder
intcount = sngInput \ 5
sngInput = sngInput Mod 5
'put in on the interface
txt05.Text = intcount
'reset the counter for the next coin value
intcount = 0
End If
'when we get here all we have left is pennies
'force the check box to be checked
chk01.Checked = True
intcount = sngInput
txt01.Text = intcount
End If
```

Hope this helps

### #3 TheNewGuy

Reputation: 0
• Posts: 4
• Joined: 23-April 07

## Re: Change Maker

Posted 23 April 2007 - 08:13 PM

WOW, that was a fast reply. I love this forum. And this did the trick after I changed the checked box names.

Thank you

I have been working on this for days and it is due tomorrow

### #4 Goddard

Reputation: 1
• Posts: 25
• Joined: 23-April 07

## Re: Change Maker

Posted 23 April 2007 - 08:15 PM

No Problem, glad I was of service.

Your right, this is a great forum.