In: Computer Science
Goal:
After the manager of a local McDonalds hired several ASU grads to work the cash registers, he realized that they were having trouble figuring out the correct amount of change to return to their customers. The manager wants you to create a VB.NET program that calculates the correct amount of change to be given to a customer following a transaction.
Guidelines:
You should have
Inputs:
Transaction Amount
validation: data must have been entered, data must be numeric, amount cannot be negative or greater than $1000.00
Amount of Cash Provided By The Customer
validation: data must have been entered, data must be numeric,
amount cannot be negative and must be equal to or greater than the Transaction Amount
Outputs:
Total Amount of Change To Be Returned
Number of Twenties To Be Returned
Number of Tens To Be Returned
Number of Fives To Be Returned
Number of Ones To Be Returned
Number of Quarters To Be Returned
Number of Dimes To Be Returned
Number of Nickels To Be Returned
Number of Pennies To Be Returned
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
NOTE :HERE IMAGE IS SHOWN FOR DEMONSTRATION PURPOSE ONLY.
Here a new Windows Forms Application in VB is created using Visual Studio 2017 with name "VBChangeAmount".This application contains a form with name "Form1.vb".Below are the files associated with form1.
1.Form1.vb[Design]
2.Form1.vb
Option Explicit On
Option Strict On
Public Class Form1
'Calculate button click
Private Sub btnChange_Click(sender As Object, e As EventArgs)
Handles btnChange.Click
'declaring variables
Dim twenties As Integer
Dim tens As Integer
Dim fives As Integer
Dim ones As Integer
Dim quarters As Integer
Dim dimes As Integer
Dim nickels As Integer
Dim pennis As Integer
Dim cents As Integer
Dim amount As Integer 'variable to store amount
' If Integer.TryParse(txtTransaction.Text, amount) Then
'when valid transaction amount is entered
amount = Integer.Parse(txtTransaction.Text)
If amount > 0 And amount <= 1000 Then
'if amount between 0 to 1000 entered then
cents = amount 'storing amount
'checking amount
If amount >= 20 Then
twenties = CInt(Fix(amount / 20)) 'finding twenties
amount = amount Mod 20 'finding remaining amount
End If
'checking amount
If amount >= 10 Then
tens = CInt(Fix(amount / 10)) 'finding tens
amount = amount Mod 10 'finding remaining amount
End If
'checking amount
If amount >= 5 Then
fives = CInt(Fix(amount / 5)) 'finding fives
amount = amount Mod 5 'finding remaining amount
End If
'checking amount
If amount >= 1 Then
ones = CInt(Fix(amount)) 'finding ones
End If
'finding quarters, dimes , nickels and pennis
'checking cents
If cents >= 25 Then
quarters = CInt(Fix(cents / 25)) 'finding quarters
cents = cents Mod 25 'finding remaining amount
End If
'checking cents
If cents >= 10 Then
dimes = CInt(Fix(cents / 10)) 'finding dimes
cents = cents Mod 10 'finding remaining amount
End If
'checking cents
If cents >= 5 Then
nickels = CInt(Fix(cents / 5)) 'finding nickels
cents = cents Mod 5 'finding remaining amount
End If
'checking cents
If cents >= 1 Then
pennis = CInt(Convert.ToInt32(cents)) 'finding pennis
End If
'display details on the label
lblChangeAmount.Text = "Total Amount of Change : " &
txtTransaction.Text & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of
Twenties : " & twenties & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of Tens :
" & tens & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of Fives
: " & fives & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of Ones :
" & ones & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of
Quarters : " & quarters & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of Dimes
: " & dimes & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of
Nickels : " & nickels & Environment.NewLine
lblChangeAmount.Text = lblChangeAmount.Text & "Number of
Pennies : " & pennis & Environment.NewLine
Else
'if amount is not in the range
lblChangeAmount.Text = "Enter valid amount between 0 to 1000"
End If
' Else
'if non numeric amount is entered
'lblChangeAmount.Text = "Enter valid transaction amount in
numbers"
' End If
End Sub
'clear button click
Private Sub btnClear_Click(sender As Object, e As EventArgs)
Handles btnClear.Click
lblChangeAmount.Text = ""
txtTransaction.Text = ""
End Sub
'Exit button click
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles
btnExit.Click
Me.Close() 'when this button clicked close form
End Sub
End Class
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2 :Screen when invalid transaction amount is entered
Screen 3 :Screen showing details
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.