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

Trying to solve this and have gotten close but need help. Please don\'t use adva

ID: 3583922 • Letter: T

Question

Trying to solve this and have gotten close but need help.

Please don't use advance coding this is introduction to programing in Visual Basic. This focuses on Sub procedures.

Here is a link to someone who got very close but did not add the totals for the total quantities of each item as shown in the image below.

https://youtu.be/VQqh-OEUqW4

2. Restaurant Bill A fast-food vendor sells pizza slices ($1.75), fries ($2.00), and soft drinks ($1.25). Write a program to compute a customers bill. The program should request the

Explanation / Answer

Hope this will help out.

Public Class frmBill

    ' Declare global constants and variables

    Const PIZZA_PRICE As Double = 5.25

    Const FRIES_PRICE As Double = 8

    Const DRINKS_PRICE As Double = 6.25

    Dim numberOfSlices As Integer = 0

    Dim numberOfFries As Integer = 0

    Dim numberOfDrinks As Integer = 0

    Dim pizzaCost As Double = 0

    Dim friesCost As Double = 0

    Dim drinksCost As Double = 0

    Dim total As Double = 0

    Dim valid As Boolean = True ' variable to make sure input is valid before displaying the bill

    Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click

        lstOutput.Items.Clear()

        InputData()

        total = TotalCost()

        If valid = True Then

            DisplayBill()

        End If

    End Sub

    Sub InputData()

        ' Validates the input from the user and assigns the values to the appropriate variables

        valid = True ' Initialize to true in case of prior invalid input

        If IsNumeric(txtPizza.Text) Then

            If CInt(txtPizza.Text) >= 0 Then

                numberOfSlices = CInt(txtPizza.Text)

            Else

                MessageBox.Show("You entered a negative number. Please try again.")

                valid = False

            End If

        Else

            MessageBox.Show("You did not enter a numeric value. Please try again.")

            valid = False

        End If

        If IsNumeric(txtFries.Text) Then

            If CInt(txtFries.Text) >= 0 Then

                numberOfFries = CInt(txtFries.Text)

            Else

                MessageBox.Show("You entered a negative number. Please try again.")

                valid = False

            End If

        Else

            MessageBox.Show("You did not enter a numeric value. Please try again.")

            valid = False

        End If

        If IsNumeric(txtDrinks.Text) Then

            If CInt(txtDrinks.Text) >= 0 Then

                numberOfDrinks = CInt(txtDrinks.Text)

            Else

                MessageBox.Show("You entered a negative number. Please try again.")

                valid = False

            End If

        Else

            MessageBox.Show("You did not enter a numeric value. Please try again.")

            valid = False

        End If

    End Sub

    Function TotalCost() As Double

        ' Calculates and returns the total cost of food

        pizzaCost = numberOfSlices * PIZZA_PRICE

        friesCost = numberOfFries * FRIES_PRICE

        drinksCost = numberOfDrinks * DRINKS_PRICE

        Return pizzaCost + friesCost + drinksCost

    End Function

    Sub DisplayBill()

        ' Displays the customer's bill in the list box

        lstOutput.Items.Add("ITEM          QUANTITY     PRICE")

        lstOutput.Items.Add("pizza slices      " & numberOfSlices & "        " & (pizzaCost).ToString("C"))

        lstOutput.Items.Add("fries             " & numberOfFries & "        " & (friesCost).ToString("C"))

        lstOutput.Items.Add("soft drinks       " & numberOfDrinks & "        " & (drinksCost).ToString("C"))

        lstOutput.Items.Add("TOTAL                      " & (total).ToString("C"))

    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