cash register - newbie needs help!

overeasy

New member
Joined
Apr 9, 2006
Messages
2
Programming Experience
Beginner
hello all! im really new to .Net and i have done my best to workout a solution for this challenge but i keep hitting walls. i would appreciate it if some1 could help me with it, thanks in advance!!
My application is 99% complete except for this 1 problem:
the program is meant to calcualte exact change from the purchase and amount tended and then display the denomination of change in individual txtboxes ie 1 for each denomination

it calculates the change and displays it in a txtbox with no probs

Im having problems displaying just 1 pence's
for example: enter £1.99 as cost, enter £5 as tendered and it displays the correct change £3.01 but in the denomination txtboxes it displays a £2 coin and a £1 coin but no 1 penny, its the same for every amount i enter.
please help if u can and have a pleasant Easter!

PS I KNOW MY CODE IS PRETTY CRAP AND THERE BETTER MORE EFFICIOENT WAYS BUT I'LL LEARN FROM MY MISTAKES -I JUST NEED THE 1PENCE ISSUE SORTED AND IM HAPPY FOR NOW, THANKS.

heres what ive done so far...

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

'verifify login

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")

'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
While Change > 0.01
Change = Change - 0.01
i = i + 1
End While
txt01p.Text = i & " "
i = 0
End Sub
 
try changing this:
While Change > 0.01
Change = Change - 0.01
i = i + 1
End While
txt01p.Text = i & " "

to this:
Dim Pence As Integer = CInt(Change * 100)
txt01p.Text = Pence & " "

You have already subtracted all other change values - what is left is just pence.
 
thankyou

That was just what the docter ordered. it works a treat now and i thank you for your time, i appreciate it! :) :) :)
 
Back
Top