locked
I am Having Trouble!

    Question

  • I am doing a project for school and i have to make a program that pretty much has you order a pizza and i am having trouble putting the code in to total the money when i select the size of pizza and the toppings... Here's the code i have now...
        Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click
            If Val((Price.Text) >= 1) Then
                Val((Price.Text) = 6.0)
    
            End If
    
        End Sub
    
        Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
            If Regular.Checked = True Then
                Regular.Checked = False
            End If
            If Large.Checked = True Then
                Large.Checked = False
            End If
            If Family.Checked = True Then
                Family.Checked = False
            End If
            If Pepperoni.Checked = True Then
                Pepperoni.Checked = False
            End If
            If Mushrooms.Checked = True Then
                Mushrooms.Checked = False
            End If
            If HotPeppers.Checked = True Then
                HotPeppers.Checked = False
            End If
            If GreenPeppers.Checked = True Then
                GreenPeppers.Checked = False
            End If
            If Onions.Checked = True Then
                Onions.Checked = False
            End If
            If Ham.Checked = True Then
                Ham.Checked = False
            End If
        End Sub
    ... i don't have to add anything else to the form display.


    Sunday, December 06, 2009 9:11 PM

Answers

  • At this point don't you know how to declare a variable?


    normally I wouldn't go this far for homework, but I'll outline it for you. You need to do the rest.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim  'my Double variable
    
    
            Select Case  'which radiobutton is checked
                Case  'radiobutton for small
                    'my Double variable =  some price
                Case  'radiobutton for large
                    'my Double variable =  some price
                Case  'radiobutton for family
                    'my Double variable =  some price
            End Select
    
            If...Then  'block going through all the checkboxes for toppings
                'Double variable = double variable + some cose for the topping
            End If
    
            'Cost of pizza = the value of the Double variable
    
        End Sub
    Sunday, December 06, 2009 10:29 PM
  •         '=====================
            ' jwavila has you started in the right direction.
            ' I find that a problem can often be made easier to solve by writing the steps out.
            '=====================
    
            '=====================
            ' We need a variable to hold the cost as calculate it
            '=====================
            Dim pizzaCost As Double = 0             'we will reset based on size
            '=====================
    
            '=====================
            ' We need to estabilish a base cost of a cheese pizza as determined by size
            ' Since a pizza can only ever be of one size jwavila uses a set of radio buttons
            '=====================
            ' pizzaCost = ???
            '      This will take several lines to properly figure out.
            '           If the smallRadioButton is selected we will use the smallCost
            '           If the medRadioButton is selected we will use the medCost
            '           If the largeRadioButton is selected we will use the largeCost
            '=====================
    
            '=====================
            ' Now let's count up the number of toppings.
            ' Toppings will add a fixed cost per item to the base.
            '=====================
            Dim toppingCost As Double = 0.75        'each topping will cost $0.75
            Dim toppinCount As Int32 = 0            'we will count them up in the next step
    
            ' toppinCount = ???
            '      This will take several lines to properly figure out.
            '           If the mushroomCheckbox is checked add 1 to the count
            '           If the pepperoniCheckbox is checked add 1 to the count
            '           ....
    
            pizzaCost += toppingCost * toppinCount
            '=====================
    
            '=====================
            ' Finally, let's report back what the total cost is
            '=====================
            MessageBox.Show(String.Format("The cost comes to: {0:C2}", pizzaCost))
            '=====================
    
    Monday, December 07, 2009 3:13 PM
  • Well, I would separate some of this.

    I would use 3 radiobuttons in a GroupBox for the sizes, since you can only select 1 size pizza. Then checkboxes for all the other toppings that can be selected, in another groupbox.


    Start with a "base" price for the pizza as a Double variable based on the size ordered. So use a Select Case to determine which radiobutton is selected, and set your base price = price for that size

    Then for the toppings, you have to decide on a price for each topping. Go through all the checkboxes as you did to clear them, but instead add the price of that topping to the Pizza price. At the end of the Sub you'll have your total cost for the pizza.
    Sunday, December 06, 2009 9:40 PM

All replies

  • Well, I would separate some of this.

    I would use 3 radiobuttons in a GroupBox for the sizes, since you can only select 1 size pizza. Then checkboxes for all the other toppings that can be selected, in another groupbox.


    Start with a "base" price for the pizza as a Double variable based on the size ordered. So use a Select Case to determine which radiobutton is selected, and set your base price = price for that size

    Then for the toppings, you have to decide on a price for each topping. Go through all the checkboxes as you did to clear them, but instead add the price of that topping to the Pizza price. At the end of the Sub you'll have your total cost for the pizza.
    Sunday, December 06, 2009 9:40 PM
  • Could you please start the code for me please? and how would i set the "base" price for the pizza as a Double variable?
    Sunday, December 06, 2009 9:52 PM
  •  

     

     

    DIM basePrice As Double = 9.95

    You need to learn to ask plenty of questions, generically. "How do I declare a double?", is an example.

    Renee
    Sunday, December 06, 2009 10:22 PM
  • At this point don't you know how to declare a variable?


    normally I wouldn't go this far for homework, but I'll outline it for you. You need to do the rest.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim  'my Double variable
    
    
            Select Case  'which radiobutton is checked
                Case  'radiobutton for small
                    'my Double variable =  some price
                Case  'radiobutton for large
                    'my Double variable =  some price
                Case  'radiobutton for family
                    'my Double variable =  some price
            End Select
    
            If...Then  'block going through all the checkboxes for toppings
                'Double variable = double variable + some cose for the topping
            End If
    
            'Cost of pizza = the value of the Double variable
    
        End Sub
    Sunday, December 06, 2009 10:29 PM
  • I still don't get it? do u have some kind of chatting program like skype or xfire?
    Sunday, December 06, 2009 10:30 PM
  • What do you not get?
    Renee
    Sunday, December 06, 2009 10:58 PM
  • I don't get
    Private
     Sub
     Button1_Click(ByVal
     sender As
     System.Object, ByVal
     e As
     System.EventArgs) Handles
     Button1.Click
    Dim 'my Double variable


    Select Case 'which radiobutton is checked
    Case 'radiobutton for small
    'my Double variable = some price
    Case 'radiobutton for large
    'my Double variable = some price
    Case 'radiobutton for family
    'my Double variable = some price
    End Select

    If ...Then 'block going through all the checkboxes for toppings
    'Double variable = double variable + some cose for the topping
    End If

    'Cost of pizza = the value of the Double variable

    End Sub
    like wut do i put in the green?
    Sunday, December 06, 2009 11:22 PM
  • What are you to bring to the table besides, "I don't understand".
    Renee
    Sunday, December 06, 2009 11:27 PM
  • I don't understand what jwavila posted up about wut i posted cause she/he has like Case...'radiobutton for small... and i don't know what to put in place of that? so if u can understand what i am trying to say that would be kool!
    Sunday, December 06, 2009 11:34 PM
  • you said this is a project for school.

    I assume you are using a textbook. Look up Select Case, Variable declaration, If...Then statement.

    If you are not using a textbook, Google the above.

    In the Search box at the top of this panel, type Select Case, etc.  You'll get lot's of examples how to use these.

    Go to MSDN and look it up there.


    We are not going to do this for you. I laid out everything you need - as I said, more than I normally would for a homework question. You just need to do some research and fill in the blanks (or rather, the green text)

    If you are not going to attempt to figure it out, it won't get done.
    Monday, December 07, 2009 12:15 AM
  • Ok. You'll do much better, if you ask specific questions.

    Renee
    Monday, December 07, 2009 12:43 AM
  •         '=====================
            ' jwavila has you started in the right direction.
            ' I find that a problem can often be made easier to solve by writing the steps out.
            '=====================
    
            '=====================
            ' We need a variable to hold the cost as calculate it
            '=====================
            Dim pizzaCost As Double = 0             'we will reset based on size
            '=====================
    
            '=====================
            ' We need to estabilish a base cost of a cheese pizza as determined by size
            ' Since a pizza can only ever be of one size jwavila uses a set of radio buttons
            '=====================
            ' pizzaCost = ???
            '      This will take several lines to properly figure out.
            '           If the smallRadioButton is selected we will use the smallCost
            '           If the medRadioButton is selected we will use the medCost
            '           If the largeRadioButton is selected we will use the largeCost
            '=====================
    
            '=====================
            ' Now let's count up the number of toppings.
            ' Toppings will add a fixed cost per item to the base.
            '=====================
            Dim toppingCost As Double = 0.75        'each topping will cost $0.75
            Dim toppinCount As Int32 = 0            'we will count them up in the next step
    
            ' toppinCount = ???
            '      This will take several lines to properly figure out.
            '           If the mushroomCheckbox is checked add 1 to the count
            '           If the pepperoniCheckbox is checked add 1 to the count
            '           ....
    
            pizzaCost += toppingCost * toppinCount
            '=====================
    
            '=====================
            ' Finally, let's report back what the total cost is
            '=====================
            MessageBox.Show(String.Format("The cost comes to: {0:C2}", pizzaCost))
            '=====================
    
    Monday, December 07, 2009 3:13 PM