Vb.net 订购系统(比萨饼)
我需要帮助创建一个比萨饼订购系统,该系统允许用户通过复选框选择大小和配料,通过数字向上向下选择数量,并允许用户在文本框中输入客户给出的数量,过程是将所选文本框的所有值相加,然后乘以数量,它还计算由于客户引起的变化,输出是在列表框中显示交易(多个)(总价、给定金额和变化) 问题在于,复选框没有添加正确的值,当单击“计算”按钮时,列表框中的值在第一次交易后加倍。以下是我的代码:Vb.net 订购系统(比萨饼),vb.net,vb.net-2010,Vb.net,Vb.net 2010,我需要帮助创建一个比萨饼订购系统,该系统允许用户通过复选框选择大小和配料,通过数字向上向下选择数量,并允许用户在文本框中输入客户给出的数量,过程是将所选文本框的所有值相加,然后乘以数量,它还计算由于客户引起的变化,输出是在列表框中显示交易(多个)(总价、给定金额和变化) 问题在于,复选框没有添加正确的值,当单击“计算”按钮时,列表框中的值在第一次交易后加倍。以下是我的代码: Public Class Form1 Dim small As Double = 25.75 Dim medium
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
如果有人能帮助我,我将不胜感激。谢谢您的事务变量永远不会重置为零。试试这个
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
pizzaSize = 0;
请更具体地说明它是如何发生故障的。例如,包括您的输入、预期输出和实际输出(或错误)。在开始添加变量之前,您从不初始化变量。这意味着,一旦输入一次并开始一个新的顺序,变量仍然包含上一个顺序末尾的值。