473,413 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Calculations

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,
Jan 18 '08 #1
7 1257
debasisdas
8,127 Expert 4TB
Great idea.

What you have done sofar to complete the task ?
Jan 18 '08 #2
This is what I have coded so far, any help you can give will be much appreciated.
Thanks


Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     'Project:  McDonald's Register
  3.  
  4.     ' Description:  This project is to make change for transactions in the proper monetary denominations.
  5.     Dim x As Decimal
  6.     'Declare variables
  7.     Dim amtOfsale As Decimal
  8.     Dim totalTendered As Decimal
  9.     Dim changeDue As Decimal
  10.     Dim coin As Decimal
  11.     Dim quarter As Decimal
  12.     Dim dime As Decimal
  13.     Dim nickel As Decimal
  14.     Dim penny As Decimal
  15.     Dim dollarChange As Decimal
  16.     Dim quarterChange As Decimal
  17.     Dim dimeChange As Decimal
  18.     Dim nickelChange As Decimal
  19.     Dim pennyChange As Decimal
  20.  
  21.  
  22.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  23.  
  24.     End Sub
  25.  
  26.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
  27.         'Sets up Currency
  28.         'Transfers the amount to the label
  29.         Label1.Text = x.ToString("C")
  30.     End Sub
  31.  
  32.     Private Sub AmtOfSaleTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmtOfSaleTextBox.TextChanged
  33.         'Convert to Decimal
  34.         amtOfsale = Val(AmtOfSaleTextBox.Text)
  35.  
  36.     End Sub
  37.  
  38.     Private Sub TotalTenderedTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalTenderedTextBox.TextChanged
  39.         'Convert to Decimal
  40.         totalTendered = Val(TotalTenderedTextBox.Text)
  41.     End Sub
  42.  
  43.     Private Sub ChangeDueTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangeDueTextBox.TextChanged
  44.         'Assign value to variable
  45.         totalTendered = Decimal.Parse(Me.TotalTenderedTextBox.Text)
  46.         changeDue = Decimal.Parse(Me.ChangeDueTextBox.Text)
  47.  
  48.     End Sub
  49.  
  50.     Private Sub TwentyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TwentyTextBox.TextChanged
  51.  
  52.     End Sub
  53.  
  54.     Private Sub TenTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TenTextBox.TextChanged
  55.  
  56.     End Sub
  57.  
  58.     Private Sub FiveTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiveTextBox.TextChanged
  59.  
  60.     End Sub
  61.  
  62.     Private Sub OneTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OneTextBox.TextChanged
  63.  
  64.     End Sub
  65.  
  66.     Private Sub QuartersTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuartersTextBox.TextChanged
  67.         If coin > 75 Then
  68.             quarter = 3
  69.             coin = coin - 75
  70.         ElseIf coin > 50 Then
  71.             quarter = 2
  72.             coin = coin - 50
  73.         ElseIf coin > 25 Then
  74.             quarter = 1
  75.             coin = coin - 25
  76.         Else
  77.             quarter = 0
  78.  
  79.         End If
  80.         QuartersTextBox.Text = quarter
  81.     End Sub
  82.  
  83.     Private Sub DimesTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DimesTextBox.TextChanged
  84.         If coin > 20 Then
  85.             dime = 2
  86.             coin = coin - 20
  87.         ElseIf coin > 10 Then
  88.             dime = 1
  89.             coin = coin - 10
  90.         Else
  91.             dime = 0
  92.         End If
  93.     End Sub
  94.  
  95.     Private Sub NickelsTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NickelsTextBox.TextChanged
  96.         If coin > 5 Then
  97.             nickel = 1
  98.             coin = coin - 5
  99.         End If
  100.     End Sub
  101.  
  102.     Private Sub PenniesTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PenniesTextBox.TextChanged
  103.         If coin = 4 Then
  104.             penny = 4
  105.             coin = coin - 4
  106.         ElseIf coin = 3 Then
  107.             penny = 3
  108.             coin = coin - 3
  109.         ElseIf coin = 2 Then
  110.             penny = 2
  111.             coin = coin - 2
  112.         ElseIf coin = 1 Then
  113.             penny = 1
  114.             coin = coin - 1
  115.         End If
  116.  
  117.     End Sub
  118.  
  119.     Private Sub ClearSalesButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearSalesButton.Click
  120.  
  121.     End Sub
  122.  
  123.     Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click
  124.         'Calculate a total.
  125.         changeDue = (TotalTenderedTextBox.Text - AmtOfSaleTextBox.Text)
  126.         ChangeDueTextBox.Text = amtOfsale.ToString
  127.     End Sub
  128. End Class
Jan 21 '08 #3
Killer42
8,435 Expert 8TB
Can you give us some idea of what problem you have, or what you want help with? I mean something a bit more specific?
Jan 22 '08 #4
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,
Jan 22 '08 #5
QVeen72
1,445 Expert 1GB
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub AmtOfSaleTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmtOfSaleTextBox.TextChanged
  2.         'Convert to Decimal
  3.         amtOfsale = Val(AmtOfSaleTextBox.Text)
  4.         ChangeDue = TotalTendered - amtOfSale 
  5.         ChangeDueTextBox = Format(ChangeDue,"0.00")
  6.     End Sub
  7.  
  8.     Private Sub TotalTenderedTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalTenderedTextBox.TextChanged
  9.         'Convert to Decimal
  10.         totalTendered = Val(TotalTenderedTextBox.Text)
  11.         ChangeDue = TotalTendered - amtOfSale 
  12.         ChangeDueTextBox = Format(ChangeDue,"0.00")
  13.     End Sub
  14.  
  15.  

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
Jan 22 '08 #6
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,
Jan 26 '08 #7
Killer42
8,435 Expert 8TB
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.
Jan 27 '08 #8

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

Similar topics

2
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...
0
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...
4
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...
11
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...
3
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...
3
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...
0
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....
13
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...
1
by: Grubsy4u | last post by:
Grubsy4u Newbie 7 Posts October 5th, 2007 11:31 AM #1 Report calculations --------------------------------------------------------------------------------
9
Catalyst159
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...
0
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
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...

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.