I am trying to write a Program that calculates a Bill for a Pizza Shop

Hello Have tried writing the code but cannot seem to get it to display

Page 1 of 1

3 Replies - 3564 Views - Last Post: 12 October 2009 - 08:16 AM Rate Topic: -----

#1 JJS1968  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 09

I am trying to write a Program that calculates a Bill for a Pizza Shop

Post icon  Posted 12 October 2009 - 06:12 AM

Hello I hope someone can help me I am trying to write a program that compute the bill for a pizza shop and I cannot figure out what I am doing wrong when I build it there are no errors but when I debug it it will not run I just cannot figure it out so I was hoping someone could help me figure out what I am doing wrong it is being written in Visual Basic 2008 well anyway here is the code.

Public Class Bill
Private Sub Compute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Compute.Click
Dim fmtstr As String = "{0,-16}{1,12}{2,12}"
lstTotal.Items.Clear()
lstTotal.Items.Add(String.Format(fmtstr, "Item", "Quantity", "Price"))
lstTotal.Items.Add(String.Format(fmtstr, "Pizza", "", "$1.75"))
lstTotal.Items.Add(String.Format(fmtstr, "Fries", "", "$2.00"))
lstTotal.Items.Add(String.Format(fmtstr, "SoftDrinks", "", "$1.25"))
lstTotal.Items.Add(String.Format(fmtstr, "Total"))
Dim Pizza As Double
Dim Fries As Double
Dim SoftDrinks As Double
Dim Bill As Double = (Pizza * 1.75 + Fries * 2 + SoftDrinks * 1.25)
Dim Total = lstTotal.Text

End Sub
Sub InputData(ByRef Pizza As Double, ByRef Fries As Double, ByRef SoftDrinks As Double)
Pizza = CDbl(lstTotal.Text)
Fries = CDbl(lstTotal.Text)
SoftDrinks = CDbl(lstTotal.Text)
End Sub
Sub DisplayTotal(ByVal Pizza As Double, ByVal Fries As Double, ByVal SoftDrinks As Double)
Dim Total As Double
Total = FormatCurrency(Pizza, Fries, SoftDrinks)
lstTotal.Text = FormatCurrency(Total)
End Sub
Function Total(ByVal Pizza As Double, ByVal Fries As Double, ByVal SoftDrinks As Double)
Dim Price As Double
Dim Quantity As Double
Total = Price * Quantity
Return Price * ((1 + Total) * Quantity)

End Function
End Class

Is This A Good Question/Topic? 0
  • +

Replies To: I am trying to write a Program that calculates a Bill for a Pizza Shop

#2 xtreampb  Icon User is offline

  • D.I.C Regular

Reputation: 13
  • View blog
  • Posts: 310
  • Joined: 20-June 07

Re: I am trying to write a Program that calculates a Bill for a Pizza Shop

Posted 12 October 2009 - 07:54 AM

what do you mean it will not run. some more details would be nice. thanks
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: I am trying to write a Program that calculates a Bill for a Pizza Shop

Posted 12 October 2009 - 08:04 AM

Well, first off, the following line will produce an error
lstTotal.Items.Add(String.Format(fmtstr, "Total"))
'this should read
lstTotal.Items.Add(String.Format(fmtstr, "Total","",""))
'or something like that to handle the other two fields.



Is this a school project and if so, does it specify what controls are to be used?

If not, a listview would be a better list control for what you are appearing to try to do.

This post has been edited by CharlieMay: 12 October 2009 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 JJS1968  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 09

Re: I am trying to write a Program that calculates a Bill for a Pizza Shop

Posted 12 October 2009 - 08:16 AM

View PostCharlieMay, on 12 Oct, 2009 - 07:04 AM, said:

Well, first off, the following line will produce an error
lstTotal.Items.Add(String.Format(fmtstr, "Total"))
'this should read
lstTotal.Items.Add(String.Format(fmtstr, "Total","",""))
'or something like that to handle the other two fields.



Is this a school project and if so, does it specify what controls are to be used?

If not, a listview would be a better list control for what you are appearing to try to do.



Yes thisis a school project and it is supposed to caculate the number if slices of Pizza, Fries and Soft Drinks now I was p[laying with it a little more and was able to get the dtat to display but for some reason am unable to get it to calculate the form has 3 text boxes for input one button to compute 3 lables and one list box to diplay the qunatity of the items and then the total but that is where I am stuck it will not calculate it at at all. Here take a look.

Public Class Bill
Private Sub Compute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Compute.Click

Dim fmtstr As String = "{0,-16}{1,12}{2,12}"
lstTotal.Items.Clear()
lstTotal.Items.Add(String.Format(fmtstr, "Item", "Quantity", "Price"))
lstTotal.Items.Add(String.Format(fmtstr, "Pizza", "", "$1.75"))
lstTotal.Items.Add(String.Format(fmtstr, "Fries", "", "$2.00"))
lstTotal.Items.Add(String.Format(fmtstr, "SoftDrinks", "", "$1.25"))
lstTotal.Items.Add("")
Dim Pizza As Double
Dim Fries As Double
Dim SoftDrinks As Double
Dim Bill As Double = (Pizza * 1.75 + Fries * 2 + SoftDrinks * 1.25)
Dim Total = lstTotal.Text
lstTotal.Items.Add(String.Format(fmtstr, "Total", "", ""))

End Sub


Sub DisplayInputData(ByRef Pizza As Double, ByRef Fries As Double, ByRef SoftDrinks As Double)
Pizza = CDbl(lstTotal.Text)
Fries = CDbl(lstTotal.Text)
SoftDrinks = CDbl(lstTotal.Text)
End Sub

Sub DisplayTotal(ByVal Pizza As Double, ByVal Fries As Double, ByVal SoftDrinks As Double)
Dim Total As Double
Total = FormatCurrency(Pizza, Fries, SoftDrinks)
lstTotal.Text = FormatCurrency(Total)
End Sub
Function Total(ByVal Pizza As Double, ByVal Fries As Double, ByVal SoftDrinks As Double)
Dim Price As Double
Dim Quantity As Double
Total = Price * Quantity
Return Price * ((1 + Total) * Quantity)

End Function



End Class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1