2016-05-09 85 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