Question

I'm Having a problem with my solution, any help would be appreciated. A fast-food vendor sells...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
I'm Having a problem with my solution, any help would be appreciated. A fast-food vendor sells...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I can't figure this one out at all. Any help would be appreciated. Here's the question:...

    I can't figure this one out at all. Any help would be appreciated. Here's the question: You will need to complete the functions to Toggle the Fries and Drinks sections by adding or removing the 'hide' CSS class I created. I have already created the function to Toggle Burgers and you can use that as an example to build out the full functionality. I have also made created the function to reset the form. Finally, to calculate the total, you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT