SubProcedures - Pizza Vendor

melwin
10-27-2009, 05:55 PM
This is my project for class and this is what i have so far but my teacher gave me no credit. What am i doing wrong? i tried re arranging but had no sucess

A fast-food vendor sells pizza slices at $1.25 each, fries at $1.00, and soft drinks at $0.75. Write a program to computer a customer’s bill. The program should use 4 subprocedures that do the following:
1. read in the amount of each item ordered
2. calculate the total cost
3. display an itemized bill
4. read in the user’s full name from a textbox, and display a sentence, addressing the user by first name only and in upper case characters, informing the user of their bill
Here is an example itemized bill:
Item Quantity Price
Pizza slices 3 $1.25
Fries 4 $1
Soft drinks 5 $0.75
Total $11.50
Example sentence for point 4: if the user’s name was entered as “John Smith”, you would display the sentence “JOHN, your bill is $11.50”.


MY CODE:
Public Class Form1

Sub pizza(ByVal pizzap As Double, ByVal pizzanum As Double)
lstoutput.Items.Add("Pizza Slices" & pizzap & "and" & pizzanum & "is" & (pizzap * pizzanum) & ".")

End Sub
Sub fries(ByVal friesp As Double, ByVal friesnum As Double)
lstoutput.Items.Add("Fries" & friesp & "and" & friesnum & "is" & (friesp * friesnum) & ".")

End Sub
Sub drinks(ByVal drinksp As Double, ByVal drinksnum As Double)
lstoutput.Items.Add("Fries" & drinksp & "and" & drinksnum & "is" & (drinksp * drinksnum) & ".")

End Sub
Sub names(ByVal name As String, ByVal firstname As String)
lstoutput.Items.Add("Name" & firstname & ".")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pizzap, pizzanum, friesp, friesnum, drinksp, drinksnum, total As Double
Dim name As String = ""
Dim firstname As String
Dim positionOfSpace As Integer

Dim fmtstr As String = "{0,-19}{1,17}{2,14:C}"

pizzap = CDbl(txtpizza.Text)
pizzanum = 1.25
pizza(pizzap, pizzanum)

friesp = CDbl(txtfries.Text)
friesnum = 1.0
fries(friesp, friesnum)

drinksp = CDbl(txtsoftdrinks.Text)
drinksnum = 0.75
drinks(drinksp, drinksnum)

name = UCase(fname.Text)

positionOfSpace = name.IndexOf(" ")

firstname = name.Substring(0, positionOfSpace)


total = (pizzap * pizzanum) + (friesp * friesnum) + (drinksp * drinksnum)



lstoutput.Items.Clear()

lstoutput.Items.Add(String.Format(fmtstr, "Item", "Quantity", "Price"))

lstoutput.Items.Add(String.Format(fmtstr, "", "", ""))

lstoutput.Items.Add(String.Format(fmtstr, "pizza slices", pizzap, 1.25))

lstoutput.Items.Add(String.Format(fmtstr, "fries", friesp, 1.0))

lstoutput.Items.Add(String.Format(fmtstr, "soft drinks", drinksp, 0.75))

lstoutput.Items.Add(String.Format(fmtstr, "", "", ""))

lstoutput.Items.Add(String.Format(fmtstr, "Total", "", total))

lstoutput.Items.Add(String.Format(fmtstr, "", "", ""))

lstoutput.Items.Add(firstname & " , your bill is $" & total)

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub


End Class

Iceplug
10-28-2009, 04:56 PM
Well, I assume you are actually using VB.NET and not VB4/5/6.
When your assignment says
The program should use 4 subprocedures that do the following:
I take it that you should have one procedure that reads in the amount of each item ordered, another that calculates the total cost, a third to display an itemized bill, and a fourth to "read in the user’s full name from a textbox, and display a sentence, addressing the user by first name only and in upper case characters, informing the user of their bill"

Your program works pretty well - there are a few unnecessary things - your four subroutines add items to the listbox when you promptly dump them from the listbox without ever using the items in the listbox. I'd get rid of that. Also, to add an empty line to a listbox, just put listboxname.Items.Add("").

That being said, the most likely reason you received no credit is maybe your teacher wanted the subroutines as specified above - I'd talk to the teacher to see if you had a misunderstanding of what was expected.

ladyjams
01-03-2010, 10:56 AM
I have the same assignemnt and I wrote the following code. It doesn't work. Can anyone help me?

Class frmBill

Dim amtPizza As Integer
Dim amtFries As Integer
Dim amtDrinks As Integer
Dim feePizza As Double = 1.75
Dim feeFries As Double = 2.0
Dim feeDrinks As Double = 1.25
Dim SubTotal As Double = 0.0

Private Sub ReadItemQuantity()
Try
amtPizza = Convert.ToInt32(txtAmtPizza.Text)
amtFries = Convert.ToInt32(txtAmtFries.Text)
amtDrinks = Convert.ToInt32(txtAmtDrinks.Text)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function GetGrandTotal() As Double
SubTotal = 0.0
SubTotal += amtPizza * feePizza
SubTotal += amtFries * feeFries
SubTotal += amtDrinks * feeDrinks
Return SubTotal
End Function
Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
ReadItemQuantity()
DisplayBill()
End Sub
Private Sub DisplayBill()
txtAmtPizza.Text = Convert.ToString(amtPizza * feePizza)
txtAmtFries.Text = Convert.ToString(amtFries * feeFries)
txtAmtDrinks.Text = Convert.ToString(amtDrinks * feeDrinks)
txtBill.Text = GetGrandTotal().ToString()
Me.Height = 354

End Sub
End Class

Iceplug
01-03-2010, 05:04 PM
Please provide more detail than 'it doesn't work'. The original thread is over a month old and 'doesn't work' describes most of the problems on the forum. What happens and what do you want to happen?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum