vb.net 点餐系统(比萨)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29612128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ordering system (pizza)
提问by King Wizard
i need help creating a pizza ordering system that allows the user to select size and toppings by checkboxes , quantity by a numeric up down and allows the user to enter the amount given by the customer in a textbox, the process is to add up all the values of the selected textboxes and together and multiply it by the quantity, it also calculates the change due to the customer, the output is to display the transactions(multiple) in a listbox(total price, amount given and change).
我需要帮助创建一个披萨订购系统,该系统允许用户通过复选框选择大小和浇头,通过数字向上向下选择数量,并允许用户在文本框中输入客户提供的数量,过程是将所有所选文本框的值并一起乘以数量,它还计算由于客户而引起的变化,输出是在列表框中显示交易(多个)(总价,给定金额和变化)。
The problem is with regards to the checkboxes not adding up the correct values and when the calculate button is clicked and the values in the listbox are doubled after the 1st transaction.Here is my code:
问题在于复选框没有加起来正确的值,当点击计算按钮时,列表框中的值在第一次交易后加倍。这是我的代码:
Public Class Form1
Dim small As Double = 25.75
Dim medium As Double = 69.46
Dim large As Double = 98.21
Dim extraCheese As Double = 5.12
Dim mushrooms As Double = 5.75
Dim blackOlives As Double = 5.25
Dim onions As Double = 4.0
Dim greenPepper As Double = 4.5
Dim tomatoes As Double = 4.25
Dim change As Double
Dim total As Double
Dim amountGiven As Double
Dim pizzaSize As Double
Dim pizzaToppings As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (smallCheckbox.Checked) = True Then
pizzaSize = pizzaSize + small
End If
If mediumCheckbox.Checked = True Then
pizzaSize = pizzaSize + medium
End If
If largeCheckbox.Checked = True Then
pizzaSize = pizzaSize + large
End If
If extraCheeseCheckbox.Checked = True Then
pizzaToppings = pizzaToppings + extraCheese
End If
If mushroomsCheckbox.Checked = True Then
pizzaToppings = pizzaToppings + mushrooms
End If
If blackOlivesCheckbox.Checked = True Then
pizzaToppings = pizzaToppings + blackOlives
End If
If onionsCheckbox.Checked = True Then
pizzaToppings = pizzaToppings + onions
End If
If greenPepperCheckbox.Checked = True Then
pizzaToppings = pizzaToppings + greenPepper
End If
If tomatoesCheckbox.Checked = True Then
pizzaToppings = pizzaToppings + tomatoes
End If
total = (pizzaSize + pizzaToppings) * NumericUpDown1.Value
totalTextbox.Text = total
amountGiven = TextBox2.Text
change = amountGiven - total
TextBox3.Text = change
ListBox1.Items.Add("==========================================")
If smallCheckbox.Checked Then
ListBox1.Items.Add("Pizza size : Small")
End If
If mediumCheckbox.Checked Then
ListBox1.Items.Add("Pizza size : Medium")
End If
If largeCheckbox.Checked Then
ListBox1.Items.Add("Pizza size : Large")
End If
ListBox1.Items.Add("Quantity : " & NumericUpDown1.Value)
ListBox1.Items.Add("Total Cost : " & total.ToString )
ListBox1.Items.Add("Amount Tendered : " & amountGiven)
ListBox1.Items.Add("Change : " & change)
ListBox1.Items.Add("==========================================")
ListBox1.Items.Add(" ")
ListBox1.Items.Add("==========================================")
End Sub
If someone could please assist me it would be much appreciated. Thank you
如果有人可以帮助我,将不胜感激。谢谢
回答by Dan
Your transaction variables are never reset to zero. Try this,
您的交易变量永远不会重置为零。尝试这个,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
pizzaSize = 0;

