2016-05-09 56 views
-1

我正在处理一个班级任务,其中用户为每顿饭选择单选按钮。当用户输入一个忠诚号码时,我目前遇到了麻烦。该书说,如果用户输入一个忠诚度数字,它会扣除客户每获得10分的总订单成本的5%。如果客户忠诚度超过其订单的全部成本,则客户无法收回款项。计算程序时没有得到正确的结果

Private Sub btnCalculate_Click(sender As Object, 
       e As EventArgs) Handles btnCalculate.Click 

    Dim decCostofMeal As Decimal 
    Dim decEstimateCost As Decimal 
    Dim decLoyal As Decimal 
    Dim decRoastedGarlic As Decimal = 3.99D 
    Dim decFalafel As Decimal = 5.99D 
    Dim decBabaganush As Decimal = 7.99D 
    Dim decChicken As Decimal = 9.99D 
    Dim decMushroom As Decimal = 6.99D 

    ' If user enter loyalty points ' 

    If radRoastedGarlic.Checked Then 
     decCostofMeal = decRoastedGarlic 
    ElseIf RadFalafel.Checked Then 
     decCostofMeal = decFalafel 
    ElseIf RadBabaganush.Checked Then 
     decCostofMeal = decBabaganush 
    ElseIf RadChicken.Checked Then 
     decCostofMeal = decChicken 
    ElseIf RadMushroom.Checked Then 
     decCostofMeal = decMushroom 
    End If 

    decEstimateCost = decCostofMeal 

    If IsNumeric(txtPoints.Text) Then 

     decLoyal = Convert.ToInt32(txtPoints.Text) 

     If decLoyal > 0 Then 
      decEstimateCost = decEstimateCost - (decEstimateCost * 0.05) 
     End If 
    End If 

    lblResults.Text = decEstimateCost.ToString("C") 
    lblResults.Visible = True 

End Sub 

更新 我试图执行一个case语句,但不工作的一些原因

If IsNumeric(txtPoints.Text) Then 


     decLoyal = Convert.ToInt32(txtPoints.Text) 

     Select Case decLoyal 

      Case 10 - 19 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.05) 

      Case 20 - 29 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.1) 

      Case 30 - 39 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.15) 

      Case 40 - 49 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.2) 

      Case 50 - 59 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.25) 
      Case 60 - 69 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.3) 

      Case 70 - 79 

       decEstimateCost = decEstimateCost - (decEstimateCost * 0.35) 

      Case 80 - 89 
       decEstimateCost = decEstimateCost - (decEstimateCost * 0.4) 


     End Select 
+0

而你的问题是什么?我们不是一个代码写作服务;请诚实地尝试解决问题,然后您可能会在这里获得帮助 - 只留下一个空白,希望我们会填写它可能会删除您的问题。请[请阅读这里的建议](https://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions)。 –

+0

您忘记描述*如何*它是“没有得到正确的结果”,即它们是如何不正确 – Plutonix

+0

我试图实施一个案例陈述,但不工作 – TrEy

回答

0

要提高的情况下执行,你需要写

Case 10 To 19