melwin
10-27-2009, 04: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
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