473,465 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Find Coins

1 New Member
Could you help me design an interface that will find the number of quarters, dimes, nickels, and pennies from an amount entered by the user.

I really need the code for the amount textbox and the code for the find coin button.
Oct 17 '06 #1
2 1899
peterggmss
6 New Member
Could you help me design an interface that will find the number of quarters, dimes, nickels, and pennies from an amount entered by the user.

I really need the code for the amount textbox and the code for the find coin button.
Hello,
I also need to make a similar program. I have a text box "txtChange" in which the user inputs the amount of change, in cents.

The code I have, so far, is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim txtChange As Integer
  3.     Dim Quarters As Integer
  4.     Dim Dimes As Integer
  5.     Dim Nickles As Integer
  6.     Dim Pennies As Integer
  7.     Dim NumberQuarters As Integer
  8.     Dim NumberDimes As Integer
  9.     Dim NumberNickles As Integer
  10.     Dim NumberPennies As Integer
  11. End Sub
  12. Private Sub cmdCalculate_Click()
  13.     cmdCalculate.Caption = "Re-calculate"
  14.     NumberQuarters = (txtChange / 4) Mod ___
  15.     lblNumberQuarters = NumberQuarters
  16. End Sub
  17. Private Sub cmdDone_click()
  18.     Unload frmChange
  19. End Sub
However I get stuck at the NumberQuarters = (txtChange / 4) Mod _, where I don't know what _ should be.
Oct 17 '06 #2
willakawill
1,646 Top Contributor
Could you help me design an interface that will find the number of quarters, dimes, nickels, and pennies from an amount entered by the user.

I really need the code for the amount textbox and the code for the find coin button.
This will work:
Expand|Select|Wrap|Line Numbers
  1. 'we will call the button cmdCalculate
  2. Private Sub cmdCalculate_Click()
  3.    Dim intQuarters As Integer
  4.    Dim intNickels As Integer
  5.    Dim intDimes As Integer
  6.    Dim intPennies As Integer
  7.    Dim intRemainder As Integer
  8.    Dim intAmount As Integer
  9.    Dim strFinalCount As String
  10.  
  11.     If Not IsNumeric(Me.txtAmount.Text) Then
  12.         Me.txtAmount.Text = ""
  13.         MsgBox "Please enter a number"
  14.         Me.txtAmount.SetFocus
  15.         Exit Sub
  16.     End If
  17.    'let's call the textbox txtAmount
  18.    intAmount = CInt(Me.txtAmount.Text)
  19.  
  20.    If intAmount > 99 Then
  21.       intAmount = intAmount Mod 100
  22.       If intAmount = 0 Then
  23.         MsgBox "No change!"
  24.         Exit Sub
  25.       Else
  26.         If intAmount > 24 Then
  27.             intQuarters = Fix(intAmount / 25)
  28.             intAmount = intAmount Mod 25
  29.             If intAmount > 9 Then
  30.                 intDimes = Fix(intAmount / 10)
  31.                 intAmount = intAmount Mod 10
  32.                 If intAmount > 4 Then
  33.                     intNickels = Fix(intAmount / 5)
  34.                     intPennies = intAmount Mod 5
  35.                 Else
  36.                     intPennies = intAmount
  37.                 End If
  38.             Else
  39.                 If intAmount > 4 Then
  40.                     intNickels = Fix(intAmount / 5)
  41.                     intPennies = intAmount Mod 5
  42.                 Else
  43.                     intPennies = intAmount
  44.                 End If
  45.             End If
  46.         Else
  47.             If intAmount > 9 Then
  48.                 intDimes = Fix(intAmount / 10)
  49.                 intAmount = intAmount Mod 10
  50.                 If intAmount > 4 Then
  51.                     intNickels = Fix(intAmount / 5)
  52.                     intPennies = intAmount Mod 5
  53.                 Else
  54.                     intPennies = intAmount
  55.                 End If
  56.             Else
  57.                 If intAmount > 4 Then
  58.                     intNickels = Fix(intAmount / 5)
  59.                     intPennies = intAmount Mod 5
  60.                 Else
  61.                     intPennies = intAmount
  62.                 End If
  63.             End If
  64.         End If
  65.       End If
  66.     Else
  67.         If intAmount = 0 Then
  68.             MsgBox "No change!"
  69.             Exit Sub
  70.         Else
  71.         If intAmount > 24 Then
  72.             intQuarters = Fix(intAmount / 25)
  73.             intAmount = intAmount Mod 25
  74.             If intAmount > 9 Then
  75.                 intDimes = Fix(intAmount / 10)
  76.                 intAmount = intAmount Mod 10
  77.                 If intAmount > 4 Then
  78.                     intNickels = Fix(intAmount / 5)
  79.                     intPennies = intAmount Mod 5
  80.                 Else
  81.                     intPennies = intAmount
  82.                 End If
  83.             Else
  84.                 If intAmount > 4 Then
  85.                     intNickels = Fix(intAmount / 5)
  86.                     intPennies = intAmount Mod 5
  87.                 Else
  88.                     intPennies = intAmount
  89.                 End If
  90.             End If
  91.         Else
  92.             If intAmout > 9 Then
  93.                 intDimes = Fix(intAmount / 10)
  94.                 intAmount = intAmount Mod 10
  95.                 If intAmount > 4 Then
  96.                     intNickels = Fix(intAmount / 5)
  97.                     intPennies = intAmount Mod 5
  98.                 Else
  99.                     intPennies = intAmount
  100.                 End If
  101.             Else
  102.                 If intAmount > 4 Then
  103.                     intNickels = Fix(intAmount / 5)
  104.                     intPennies = intAmount Mod 5
  105.                 Else
  106.                     intPennies = intAmount
  107.                 End If
  108.             End If
  109.         End If
  110.       End If
  111.    End If
  112.  
  113.    strFinalCount = "Change: " & vbCrLf
  114.    If intQuarters > 0 Then
  115.         If intQuarters > 1 Then
  116.             strFinalCount = strFinalCount & intQuarters & " Quarters" & vbCrLf
  117.         Else
  118.             strFinalCount = strFinalCount & "1 Quarter" & vbCrLf
  119.         End If
  120.    End If
  121.         If intDimes > 0 Then
  122.          If intDimes > 1 Then
  123.              strFinalCount = strFinalCount & intDimes & " Dimes" & vbCrLf
  124.          Else
  125.              strFinalCount = strFinalCount & "1 Dime" & vbCrLf
  126.          End If
  127.    End If
  128.    If intNickels > 0 Then
  129.         If intNickels > 1 Then
  130.             strFinalCount = strFinalCount & intNickels & " Nickels" & vbCrLf
  131.         Else
  132.             strFinalCount = strFinalCount & "1 Nickel" & vbCrLf
  133.         End If
  134.    End If
  135.    If intPennies > 0 Then
  136.         If intPennies > 1 Then
  137.             strFinalCount = strFinalCount & intPennies & " Pennies" & vbCrLf
  138.         Else
  139.             strFinalCount = strFinalCount & "1 Penny" & vbCrLf
  140.         End If
  141.    End If
  142.  
  143.    MsgBox strFinalCount
  144. End Sub
  145.  
Call the textbox 'txtAmount' and call the button 'cmdCalculate' then paste the above code into your form's code module.

The Fix() function is used to avoid rounding errors
Oct 17 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Shark1 | last post by:
Hello. I'm suppose to write a program that will match the price given by the user using the least number of coins. There are 5 different type of coins. I get this output, the count is...
0
by: amit | last post by:
I want to find out that if there is a mechanism to find a text inside a C# file and replace it with another string. I am using DTE to do it, the find proerty does it, the results are getting...
0
by: AMIT PUROHIT | last post by:
hi, this is a qry which I m stuck up with I want to find out that if there is a mechanism to find a text inside a C# file and replace it with another string. I am using DTE(EnvDTE) to do it,...
0
by: amit | last post by:
hi I have created a tool which does a find and replace thru DTE, now after it is done, it opens up a window, "FIND REACHED THE STARTING POINT OF SEARCH" I want to disbale this window...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
0
by: Derek | last post by:
I am creating an intranet using Visual Web Developer Express Edition. Everything has been working OK until yesterday when I started getting 62 messages all beginning "Could not find schema...
12
mia023
by: mia023 | last post by:
Hi i have an assignment that i don't understand and need help in. Write a program that reads in a command line integer N(number of pennies) and prints out the best way(fewest number of coins) to...
1
by: MsBarnes | last post by:
I'm a newbie to the programming field and I really need help to understand what i'm doing wrong. This is the exercise i'm working on I need to create an application that allows the users to enter...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.