Visual Basic Help!! I need the code for this program. I\'m not understanding how
ID: 3688986 • Letter: V
Question
Visual Basic Help!! I need the code for this program. I'm not understanding how to get the prices of the sizes and toppings in code
SmallTown Pizza Shop serves just two sizes of pizza, small and large, and customers can add additional toppings if desired. Write a Visual Basic program that allows the user input their selection of a large or small pizza and the “total number of toppings” desired on their pizza. A small pizza is $6.95 including one topping and $0.65 for each additional topping A large pizza is $8.75 including one topping and $0.85 for each additional topping Also solicit the customer’s phone number. The program will calculate and display the cost. The program must have three command buttons, to calculate, to clear (reset the defaults), and to exit the application. Your GUI must use appropriate controls for accepting the input from the user. Make this application look like a program that a real pizza shop would use by including an appropriate image. Use radio buttons to choose a size and check boxes to pick the toppings. Validate a maximum of 5 toppings and validate that phone number at least looks like a real phone number (7 digits). Deliverable You are expected to use proper design techniques, comments, appropriate variable names and constants, and use naming conventions where appropriate. A demo and a drop box of the source is required.
Explanation / Answer
Sub CalculatePrice() Dim PriceSize As Double Dim PriceEachTopping As Double Dim BWings As Double Dim Bread As Double Dim SodaCan As Double Dim Soda20 As Double Dim Soda2L As Double Dim OJ As Double Dim Water As Double Dim PriceToppings As Double Dim TotalOrder As Double Dim Pepperoni As Integer Dim Sausage As Integer Dim ExtraCheese As Integer Dim Onions As Integer Dim Olives As Integer ' Get the price of pizza depending on the selected size If optSmall.Value = True Then PriceSize = CDbl(txtSmall.Text) End If If optMedium.Value = True Then PriceSize = CDbl(txtMedium.Text) End If If optLarge.Value = True Then PriceSize = CDbl(txtLarge.Text) End If ' Get the price of a topping if it was selected If chkPepperoni = 1 Then Pepperoni = 1 Else Pepperoni = 0 End If If chkSausage = 1 Then Sausage = 1 Else Sausage = 0 End If If chkExtraCheese = 1 Then ExtraCheese = 1 Else ExtraCheese = 0 End If If chkOnions = 1 Then Onions = 1 Else Onions = 0 End If If chkOlives = 1 Then Olives = 1 Else Olives = 0 End If PriceEachTopping = CDbl(txtEachTopping.Text) PriceToppings = (Pepperoni + Sausage + _ ExtraCheese + Onions + Olives) * PriceEachTopping ' Calculate the price of the side dishes ' depending on the quantity entered BWings = CDbl(txtTotalWings.Text) Bread = CDbl(txtTotalBread.Text) ' Calculate the price of the drink(s) SodaCan = CDbl(txtTotalCan.Text) Soda20 = CDbl(txtTotalSoda20.Text) Soda2L = CDbl(txtTotalSoda2L.Text) OJ = CDbl(txtTotalOJ.Text) Water = CDbl(txtTotalWater.Text) TotalOrder = PriceSize + PriceToppings + BWings + Bread + _ SodaCan + Soda20 + Soda2L + OJ + Water txtTotalPrice.Text = FormatCurrency(TotalOrder) End Sub On the form double-click each radio button and each check box In their implementation, simply call the CalculatePrice() function: Private Sub chkExtraCheese_Click() CalculatePrice End Sub Private Sub chkOlives_Click() CalculatePrice End Sub Private Sub chkOnions_Click() CalculatePrice End Sub Private Sub chkPepperoni_Click() CalculatePrice End Sub Private Sub chkSausage_Click() CalculatePrice End Sub Private Sub optSmall_Click() CalculatePrice End Sub Private Sub optMedium_Click() CalculatePrice End Sub Private Sub optLarge_Click() CalculatePrice End Sub Private Sub txtLarge_Change() CalculatePrice End Sub Private Sub txtMedium_Change() CalculatePrice End Sub
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.