Hi everone!, im currently working on a cash register program wich has to meet certain tests. The problem im encountering is when im calculating the change to be given to the customer. The change is correct but it has to be displayed in such a way as to give the least amount of denomination, in other words logical! It does display the most logical denomination for nearly all transactions but some like
EG cost=£32
tendered=£50
Change=£18
problem
instead of displaying change as £10 & £5 & £2 & £1, it does the last £1 in small change!
here is the section of code, i know its pretty dodgy but i aint got time to change the whole thing - IF ANY KIND PEOPLE COULD OFFER ME A QUICK FIX SOLUTION I WOULD APPRECIATE YOUR HELP A LOT, THANXS IN ADVANCE!!!
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim password As Short
Do
password = InputBox("Please Enter Your Log In Number")
Loop Until password = "1234" Or password = "5678"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim cost As Double = CType(Me.txtCost.Text, Double)
Dim amountTended As Double
Dim Change As Double
Dim i As Double
' Get the value of the total order
cost = CDec(Me.txtCost.Text)
' The amount tended will be entered by the user
amountTended = CType(Me.txtAmounttended.Text, Integer)
' Calculate the difference of both values
Change = amountTended - cost
' Display the result in the change text box
Me.txtChange.Text = Change.ToString("C")
'Validate Data
If cost > 150 Or cost = 0 Then
MsgBox("Incorrect value Please try again!")
Else
Change = 150 - cost
End If
If cost > amountTended Then
MsgBox("Insufficient tender Please try again!")
Else
Change = amountTended - cost
End If
'count the number of notes and coins in the change (process repeated for each denomination)
While Change > 50
Change = Change - 50
i = i + 1
End While
txt50.Text = i & " "
i = 0
While Change > 20
Change = Change - 20
i = i + 1
End While
txt20.Text = i & " "
i = 0
While Change > 10
Change = Change - 10
i = i + 1
End While
txt10.Text = i & " "
i = 0
While Change > 5
Change = Change - 5
i = i + 1
End While
txt5.Text = i & " "
i = 0
While Change > 2
Change = Change - 2
i = i + 1
End While
txt2.Text = i & " "
i = 0
While Change > 1
Change = Change - 1
i = i + 1
End While
txt1.Text = i & " "
i = 0
While Change > 0.5
Change = Change - 0.5
i = i + 1
End While
txt50p.Text = i & " "
i = 0
While Change > 0.2
Change = Change - 0.2
i = i + 1
End While
txt20p.Text = i & " "
i = 0
While Change > 0.1
Change = Change - 0.1
i = i + 1
End While
txt10p.Text = i & " "
i = 0
While Change > 0.05
Change = Change - 0.05
i = i + 1
End While
txt5p.Text = i & " "
i = 0
While Change > 0.02
Change = Change - 0.02
i = i + 1
End While
txt2p.Text = i & " "
i = 0
Dim Pence As Integer = CInt(Change * 100)
txt1p.Text = Pence & " "