我需要帮助创建一个比萨饼订购系统,允许用户通过复选框选择尺寸和浇头,按数字向上选择数量,并允许用户在文本框中输入客户给出的金额,过程是添加将所选文本框的所有值加在一起并将其乘以数量,它还计算由于客户而产生的变化,输出是在列表框中显示交易(多个)(总价格,给定金额和更改)。
问题在于复选框没有添加正确的值,单击计算按钮时,列表框中的值在第一次交易后加倍。这是我的代码:
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
如果有人可以帮助我,我将不胜感激。谢谢
答案 0 :(得分:2)
您的交易变量永远不会重置为零。试试这个,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
pizzaSize = 0;