Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m Having a problem with my solution, any help would be appreciated. A fast-fo

ID: 3709452 • Letter: I

Question

I'm Having a problem with my solution, any help would be appreciated.

A fast-food vendor sells pizza slices ($1.75), fries ($2.00), and soft drinks ($1.25). Write a program to compute a customer’s bill. The program should request the quantity of each item ordered in a Sub procedure, calculate the total cost with a Function procedure, and use a Sub procedure to display an itemized bill.

Now I have the code, but the Fries and the Soft Drinks are inverse of each other.

My Code is

Public Class Form1
Private Sub BtnCompute_Click(sender As Object, e As EventArgs) Handles BtnCompute.Click

Dim Slices, Fries, Drinks As Double
Dim PizzaSlices, DecFries, SoftDrinks, Total As Double
InputData(Slices, Fries, Drinks)
Calculate(Slices, Fries, Drinks, PizzaSlices, DecFries, SoftDrinks, Total)
DisplayData(Slices, Fries, Drinks, PizzaSlices, DecFries, SoftDrinks, Total)
End Sub

Sub InPutData(ByRef Slices As Double, ByRef Fries As Double, ByRef Drinks As Double)
Slices = CDbl(TxtSlices.Text)
Fries = CDbl(TxtFries.Text)
Drinks = CDbl(TxtDrinks.Text)
End Sub

Function Calculate(ByVal Slices As Double, ByVal Drinks As Double, ByVal Fries As Double, ByRef PizzaSlices As Double, ByRef DecFries As Double, ByRef SoftDrinks As Double, ByRef Total As Double)
PizzaSlices = Slices * (1.75)
DecFries = Fries * (2.0)
SoftDrinks = Drinks * (1.25)
Total = PizzaSlices + DecFries + SoftDrinks
Return Total
End Function

Sub DisplayData(ByVal Slices As Double, ByVal Drinks As Double, ByVal Fries As Double, ByRef PizzaSlices As Double, ByRef DecFries As Double, ByRef SoftDrinks As Double, ByRef Total As Double)
FastMenu.Items.Add("ITEM " & " " & "QUANTITY " & " " & "PRICE ")
FastMenu.Items.Add("Pizza Slices" & " " & Slices & " " & FormatCurrency(PizzaSlices))
FastMenu.Items.Add("Fries" & " " & Fries & " " & FormatCurrency(DecFries))
FastMenu.Items.Add("Soft Drinks" & " " & Drinks & " " & FormatCurrency(SoftDrinks))
FastMenu.Items.Add("Total" & " " & FormatCurrency(Total))

End Sub
End Class

Explanation / Answer

When you are calling Calculate function order of arguments is Slices, Fries, Drinks, PizzaSlices, DecFries, SoftDrinks, Total.

But at the time function declaration of Calculate function order of argument is Slices, Drinks, Fries, PizzaSlices, DecFries, SoftDrinks, Total.

Here you can see order of Fries and Drinks at the time of calling Calculate function is reverse of Calculate function declaration due to which you are getting output for Fries and Drinks is reverse order.

Correct is below :

Public Class Form1

Private Sub BtnCompute_Click(args() As string)

Dim Slices, Fries, Drinks As Double

Dim PizzaSlices, DecFries, SoftDrinks, Total As Double

Slices = 10

Fries = 20

Drinks = 5

Calculate(Slices, Fries, Drinks, PizzaSlices, DecFries, SoftDrinks, Total)

DisplayData(Slices, Fries, Drinks, PizzaSlices, DecFries, SoftDrinks, Total)

End Sub

Function Calculate(ByVal Slices As Double, ByVal Fries As Double, ByVal Drinks As Double, ByRef PizzaSlices As Double, ByRef DecFries As Double, ByRef SoftDrinks As Double, ByRef Total As Double)

PizzaSlices = Slices * (1.75)

DecFries = Fries * (2.0)

SoftDrinks = Drinks * (1.25)

Total = PizzaSlices + DecFries + SoftDrinks

Return Total

End Function

Sub DisplayData(ByVal Slices As Double, ByVal Drinks As Double, ByVal Fries As Double, ByRef PizzaSlices As Double, ByRef DecFries As Double, ByRef SoftDrinks As Double, ByRef Total As Double)

Console.WriteLine("ITEM " & " " & "QUANTITY " & " " & "PRICE ")

Console.WriteLine("Pizza Slices" & " " & Slices & " " & FormatCurrency(PizzaSlices))

Console.WriteLine("Fries" & " " & Fries & " " & FormatCurrency(DecFries))

Console.WriteLine("Soft Drinks" & " " & Drinks & " " & FormatCurrency(SoftDrinks))

Console.WriteLine("Total" & " " & FormatCurrency(Total))

End Sub

End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote