9 Replies - 1910 Views - Last Post: 26 October 2009 - 01:20 PM Rate Topic: -----

#1 newtothisstuff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-October 09

Help With Pizza Program

Posted 25 October 2009 - 03:07 PM

i was doing a pizza ordering program where you choose toppings and stuff for a pizza. i am having trouble when try to program vegetables, i get the wrong total in the total label
 Public Class Form1
	Dim Meats As Decimal
	Dim Vegetables As Decimal
	Dim Price As Decimal

	

	Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
		Application.Exit()
	End Sub

	Private Sub RestartToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RestartToolStripMenuItem.Click
		Application.Restart()
	End Sub
	Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
		lblSubtotal1.Text = Format(Price, "Currency")
	End Sub
	Private Sub radSmall_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSmall.CheckedChanged
		Price = Val(Meats + Vegetables)
		Price = Price + 6.75
	End Sub

	Private Sub radMedium_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radMedium.CheckedChanged
		Price = Val(Meats + Vegetables)
		Price = Price + 8.45

	End Sub

	Private Sub radLarge_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radLarge.CheckedChanged
		Price = Val(Meats + Vegetables)
		Price = Price + 10.45
	End Sub

	Private Sub radXLarge_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radXLarge.CheckedChanged
		Price = Val(Meats + Vegetables)
		Price = Price + 13.43
	End Sub

	Private Sub chkZucchini_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkZucchini.CheckedChanged
		Vegetables = Val(Price + 0.5)
		Price = Val(Meats + Vegetables)
		Price = Price + Vegetables

	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Help With Pizza Program

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Help With Pizza Program

Posted 25 October 2009 - 04:05 PM

The Zucchini check box logic is wrong. The only content should be a line like:
Price = Val(Price + 0.5)

It is also missing any logic to remove the Zucchini. I would put some logic that sets/clears a Zucchini variable based on the state of the zucchini. It would also be better to make a pricing Sub that looks at the various check box states to make a total. The logic would be get the base price using the size and then adding Meats, Vegetables and Zucchini.
Was This Post Helpful? 0
  • +
  • -

#3 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Help With Pizza Program

Posted 25 October 2009 - 04:06 PM

I see calculations going on with very few numbers assigned to variables.
For instance:
Private Sub chkZucchini_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkZucchini.CheckedChanged
		Vegetables = Val(Price + 0.5)
		Price = Val(Meats + Vegetables)
		Price = Price + Vegetables
End Sub


If "Price" and "Meats" had a value, this would work fine.
So if another checkbox or radiobutton is checked that needs the price of vegtables to compute the calculation you will still not get a value because "vegetables = Val(Price + 0.5)" well what's is price?
I would suggest taking your code out of the checkbox and radiobutton events and putting into a button press event that tests for the values of the radiobutton and checkboxes to asign values to variables before any calculation is done.
But I'm not just picking on your Zucchini...(Ilike Zucchini) All the routines are like that

This post has been edited by dzone41: 25 October 2009 - 04:09 PM

Was This Post Helpful? 0
  • +
  • -

#4 newtothisstuff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-October 09

Re: Help With Pizza Program

Posted 25 October 2009 - 04:37 PM

View Postdzone41, on 25 Oct, 2009 - 03:06 PM, said:

I see calculations going on with very few numbers assigned to variables.
For instance:
Private Sub chkZucchini_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkZucchini.CheckedChanged
		Vegetables = Val(Price + 0.5)
		Price = Val(Meats + Vegetables)
		Price = Price + Vegetables
End Sub


If "Price" and "Meats" had a value, this would work fine.
So if another checkbox or radiobutton is checked that needs the price of vegtables to compute the calculation you will still not get a value because "vegetables = Val(Price + 0.5)" well what's is price?
I would suggest taking your code out of the checkbox and radiobutton events and putting into a button press event that tests for the values of the radiobutton and checkboxes to asign values to variables before any calculation is done.
But I'm not just picking on your Zucchini...(Ilike Zucchini) All the routines are like that

the thing is i have to use radio buttons and checkboxes, how can i declare meats and price then, i alos tried putting " Price = Val(Price + 0.5) but when you uncheck and press calculate again it adds another 50 cents
Was This Post Helpful? 0
  • +
  • -

#5 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Help With Pizza Program

Posted 25 October 2009 - 04:59 PM

Of course use the checkboxes and radiobuttons, just not their events.
Try something like this:

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Price = .00
Vegetables = .00
Meat = .00
		If chkZucchini.Checked Then
			 Vegetables = .05 
			 Price += Vegetables
		End If
		If chkMeat.Checked Then 
			 Meat = .25
			 Price += Meat
		 End If
		If radSmall.Checked then
			 Price = Meats + Vegetables + 6.75
		End If
'And so on for other sizes. ....one note: I didn't notice a price for meat
		lblSubtotal1.Text = Format(Price, "Currency")
End Sub



Hope this helps
Was This Post Helpful? 0
  • +
  • -

#6 newtothisstuff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-October 09

Re: Help With Pizza Program

Posted 25 October 2009 - 05:08 PM

View Postdzone41, on 25 Oct, 2009 - 03:59 PM, said:

Of course use the checkboxes and radiobuttons, just not their events.
Try something like this:

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Price = .00
Vegetables = .00
Meat = .00
		If chkZucchini.Checked Then
			 Vegetables = .05 
			 Price += Vegetables
		End If
		If chkMeat.Checked Then 
			 Meat = .25
			 Price += Meat
		 End If
		If radSmall.Checked then
			 Price = Meats + Vegetables + 6.75
		End If
'And so on for other sizes. ....one note: I didn't notice a price for meat
		lblSubtotal1.Text = Format(Price, "Currency")
End Sub



Hope this helps

this works but just wondering, is there any way to put the code in th checkbox, just in case my teacher wants it that way i can do it
Was This Post Helpful? 0
  • +
  • -

#7 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 277
  • Joined: 29-August 08

Re: Help With Pizza Program

Posted 25 October 2009 - 05:44 PM

double click the checkbox and put the code there.
Was This Post Helpful? 0
  • +
  • -

#8 newtothisstuff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-October 09

Re: Help With Pizza Program

Posted 25 October 2009 - 05:47 PM

View Postcamckee316, on 25 Oct, 2009 - 04:44 PM, said:

double click the checkbox and put the code there.

i know how to put code in the checkboxes, i am just wondering what to put
Was This Post Helpful? 0
  • +
  • -

#9 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Help With Pizza Program

Posted 26 October 2009 - 12:51 AM

You could set price at $0.00. Then every time a checkbox is checked you asign a price to the one variable...like vegetables, and increase the price. But if you did it this way, you would really have no reason to have different variables, just price.
Dim Price As Decimal = .00
Private Sub chkZucchini_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkZucchini.CheckedChanged
		 Price += .25
End Sub


You could use the variables Meat and Vegetables if you wanted to itemize the bill.
Word of warning....doing it this method will save the amount of the variable so if you then uncheck the box, then check it again.....that's .75 cents for Zucchini.
Was This Post Helpful? 0
  • +
  • -

#10 eworm  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 64
  • Joined: 17-March 09

Re: Help With Pizza Program

Posted 26 October 2009 - 01:20 PM

You can use the method suggested by having a button press to finalize your calculations with if/then checks on each of the check boxes/radio buttons... or if you want it to update on the fly you can assign Public variables outside of any particular procedure but within your class.

Public Class frmMain
	 Public dblTotalPrice as Double
	 '----- size of pie prices
	 Public dblSmallPie as Double = 6.00
	 Public dblMediumPie as Double = 7.00
	 Public dblLargePie as Double = 8.00
	 '----- topping prices
	 Public dblVeggie1 as Double = 0.25
	 Public dlbVeggie2 as Double = 0.25
	 Public dblVeggie3 as Double = 0.25
	 Public dblExtraCheese as Double = 0.50
	 Public ..... etc

	 Private Sub chkVeggie1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkVeggie1.CheckedChanged
	 If chkVeggie1.Checked = True then
		  dblTotalPrice = dblTotalPrice + dblVeggie1
	 Else
		  dblTotalPrice = dblTotalPrice - dblVeggie1
	 End if

	 lblTotalPrice.Text = "$" & Format(dblTotalPrice, "0.00")
End Sub



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1