TrEy TrEy - 6 months ago 14
Vb.net Question

Not getting the correct results when computing the Program

I'm working on a class assignment where the user chooses radio button for each meal. I'm currently having trouble when the user puts in a loyalty number. The book says if the user inputs a loyalty number that it deducts 5% of the total order cost for every 10 points a customer has earned. Customers cannot receive money back if their loyalty points exceed the full cost of their order.

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


Update
I tried to implement a case statement but is not working for some reason

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

Answer

To improve your case execution you need to write

Case 10 To 19
Comments