Hi,
I'm a student and new to the world of programming in Visual Basic. Can someone be so kind to assist me on setting up a program to simulate a cash register where change will be given in denominations? Or is there one out there somewhere I can use as a guide?
Your help is greatly appreciated.
thank you,
7 1257
Great idea.
What you have done sofar to complete the task ?
This is what I have coded so far, any help you can give will be much appreciated.
Thanks - Public Class Form1
-
'Project: McDonald's Register
-
-
' Description: This project is to make change for transactions in the proper monetary denominations.
-
Dim x As Decimal
-
'Declare variables
-
Dim amtOfsale As Decimal
-
Dim totalTendered As Decimal
-
Dim changeDue As Decimal
-
Dim coin As Decimal
-
Dim quarter As Decimal
-
Dim dime As Decimal
-
Dim nickel As Decimal
-
Dim penny As Decimal
-
Dim dollarChange As Decimal
-
Dim quarterChange As Decimal
-
Dim dimeChange As Decimal
-
Dim nickelChange As Decimal
-
Dim pennyChange As Decimal
-
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
-
-
End Sub
-
-
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
-
'Sets up Currency
-
'Transfers the amount to the label
-
Label1.Text = x.ToString("C")
-
End Sub
-
-
Private Sub AmtOfSaleTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmtOfSaleTextBox.TextChanged
-
'Convert to Decimal
-
amtOfsale = Val(AmtOfSaleTextBox.Text)
-
-
End Sub
-
-
Private Sub TotalTenderedTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalTenderedTextBox.TextChanged
-
'Convert to Decimal
-
totalTendered = Val(TotalTenderedTextBox.Text)
-
End Sub
-
-
Private Sub ChangeDueTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangeDueTextBox.TextChanged
-
'Assign value to variable
-
totalTendered = Decimal.Parse(Me.TotalTenderedTextBox.Text)
-
changeDue = Decimal.Parse(Me.ChangeDueTextBox.Text)
-
-
End Sub
-
-
Private Sub TwentyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TwentyTextBox.TextChanged
-
-
End Sub
-
-
Private Sub TenTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TenTextBox.TextChanged
-
-
End Sub
-
-
Private Sub FiveTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiveTextBox.TextChanged
-
-
End Sub
-
-
Private Sub OneTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OneTextBox.TextChanged
-
-
End Sub
-
-
Private Sub QuartersTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuartersTextBox.TextChanged
-
If coin > 75 Then
-
quarter = 3
-
coin = coin - 75
-
ElseIf coin > 50 Then
-
quarter = 2
-
coin = coin - 50
-
ElseIf coin > 25 Then
-
quarter = 1
-
coin = coin - 25
-
Else
-
quarter = 0
-
-
End If
-
QuartersTextBox.Text = quarter
-
End Sub
-
-
Private Sub DimesTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DimesTextBox.TextChanged
-
If coin > 20 Then
-
dime = 2
-
coin = coin - 20
-
ElseIf coin > 10 Then
-
dime = 1
-
coin = coin - 10
-
Else
-
dime = 0
-
End If
-
End Sub
-
-
Private Sub NickelsTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NickelsTextBox.TextChanged
-
If coin > 5 Then
-
nickel = 1
-
coin = coin - 5
-
End If
-
End Sub
-
-
Private Sub PenniesTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PenniesTextBox.TextChanged
-
If coin = 4 Then
-
penny = 4
-
coin = coin - 4
-
ElseIf coin = 3 Then
-
penny = 3
-
coin = coin - 3
-
ElseIf coin = 2 Then
-
penny = 2
-
coin = coin - 2
-
ElseIf coin = 1 Then
-
penny = 1
-
coin = coin - 1
-
End If
-
-
End Sub
-
-
Private Sub ClearSalesButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearSalesButton.Click
-
-
End Sub
-
-
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
-
'Calculate a total.
-
changeDue = (TotalTenderedTextBox.Text - AmtOfSaleTextBox.Text)
-
ChangeDueTextBox.Text = amtOfsale.ToString
-
End Sub
-
End Class
Can you give us some idea of what problem you have, or what you want help with? I mean something a bit more specific?
In lines 32 thru 46 I should be able to enter a dollar amount into the amount of total sales text box and have it subtracted from the total tendered text box and the value of the difference should be able to go to the change due text box. It doesn't work. Also, I am not sure that my calculation button is in the proper place or is it coded sufficiently to make the calculations work.
Can you help?
thanks,
In lines 32 thru 46 I should be able to enter a dollar amount into the amount of total sales text box and have it subtracted from the total tendered text box and the value of the difference should be able to go to the change due text box. It doesn't work. Also, I am not sure that my calculation button is in the proper place or is it coded sufficiently to make the calculations work.
Can you help?
thanks,
Hi,
Remove the Code From Change Due Text Box's Change Event, and check this code: -
Private Sub AmtOfSaleTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmtOfSaleTextBox.TextChanged
-
'Convert to Decimal
-
amtOfsale = Val(AmtOfSaleTextBox.Text)
-
ChangeDue = TotalTendered - amtOfSale
-
ChangeDueTextBox = Format(ChangeDue,"0.00")
-
End Sub
-
-
Private Sub TotalTenderedTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalTenderedTextBox.TextChanged
-
'Convert to Decimal
-
totalTendered = Val(TotalTenderedTextBox.Text)
-
ChangeDue = TotalTendered - amtOfSale
-
ChangeDueTextBox = Format(ChangeDue,"0.00")
-
End Sub
-
-
It is always a better programming practice, if you Write the Calculation Part in some Sub Procedure, and call the Proc wherever required..
Regards
Veena
Can you give me a detailed suggestion on how I should set up my calculation button to show the answers in the denominations of 20's, 10's, 5's, 1's and currency change? This is what I have so far, I'm unsure how to set it up.
Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
'Calculate a total.
changeDue = (TotalTenderedTextBox.Text - AmtOfSaleTextBox.Text)
ChangeDueTextBox.Text = amtOfsale.ToString
thanks,
It looks to me as though you have already done the work to break up the change into specific numbers of specific coins. It's just that you have tried to do it in pieces, in the TextChanged events for the textboxes which (I think) are intended to display the resulting values.
I believe you need to do the calculation in a dedicated Sub or Function routine as Veena suggested. And after calculating the amount, proceed to break it down into the different coins.
Once you've done that, display the values of the variables quarter, dime and so on in their appropriate places.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: androtech |
last post by:
Hello,
I'm looking for a function that returns a date range for a specified week
number of the year.
I'm not able to find functions like this anywhere. Any pointers/help would
be much...
|
by: Rowan |
last post by:
Howdy, I am having some trouble figuring out the best way to approach
my problem with calculations. I think I should use a view but am
having trouble with the structure.
My view needs to...
|
by: Targa |
last post by:
Trying to total some price fields in a form but doesnt work when all the
referenced form fields dont exisit.
This is for an invoice - pulled prom a database and the form doesnt always
contain the...
|
by: lduperval |
last post by:
Hi,
I`m trying to do date calculations in three types of time zones: local,
GMT and specified. The issue I am facing is that I need to be able to
specify a date in the proper time zone, and I`m...
|
by: brian kaufmann |
last post by:
Hi,
I had sent this earlier, and would appreciate any suggestions on this.
I need to make calculations for unemployment rate for three different
data sources (A,B,C) for many countries and age...
|
by: John M |
last post by:
Hi,
I've been coming up against a failure of a report to display the result of a
simple calculation. I have realised that this calculation cannot take place
unless the field I am working on is...
|
by: SJM |
last post by:
There is a database which has combo boxes to allow users to select values
from pre-set lists of common specifications. The form allows users to enter
values that are not in the dropdown lists....
|
by: fredrik.ryde |
last post by:
Hi,
I have a database which contains alot of finacial data. I want to
retreive some data, run som calculations with it, nothing complex just
simple arithmetic.
I wonder if it's faster to let...
|
by: Grubsy4u |
last post by:
Grubsy4u
Newbie
7 Posts October 5th, 2007
11:31 AM
#1
Report calculations
--------------------------------------------------------------------------------
|
by: Catalyst159 |
last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows:
Part A: Maximum FAR and Floor Area:
Part B: Gross Floor Area of...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |