我无法通过选择大小写计算正确的数字

时间:2019-03-22 19:13:08

标签: vb.net

我正在尝试使用精选案例获得打折价格,但我不断获得正常价格

我选择学生,然后单击瑜伽和私人教练选项,然后根据计算,我将11个月的费用假定为月费76.50,总计841.50,但我每月得到85,总计935。帮助谢谢

Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        Dim decMontlyFee As Decimal
        Dim decTotalFee As Decimal
        Dim discount As Double
        Dim intMonths As Integer

        Dim decAdultFee As Decimal = 40
        Dim decChildFee As Decimal = 20
        Dim decStudentFee As Decimal = 25
        Dim decSeniorFee As Decimal = 30
        Dim decYogaFee As Decimal = 10
        Dim decKarateFee As Decimal = 30
        Dim decTrainerFee As Decimal = 50


        If radAdult.Checked = True Then
            decMontlyFee = decAdultFee
        ElseIf radChild.Checked = True Then
            decMontlyFee = decChildFee
        ElseIf radStudent.Checked = True Then
            decMontlyFee = decStudentFee
        ElseIf radSenior.Checked = True Then
            decMontlyFee = decSeniorFee
        End If

        If chkYoga.Checked = True Then
            decMontlyFee += decYogaFee
        End If
        If chkTrainer.Checked = True Then
            decMontlyFee += decTrainerFee
        End If
        If chkKarate.Checked = True Then
            decMontlyFee += decKarateFee
        End If

        Select Case intMonths
            Case Is <= 3
                discount = 0
            Case 4 To 6
                discount = decMontlyFee * 0.05
            Case 7 To 9
                discount = decMontlyFee * 0.08
            Case Is >= 10
                discount = decMontlyFee * 0.1
        End Select

        decMontlyFee -= discount
        decTotalFee = decMontlyFee * txtMonths.Text

        lblMonthlyFee.Text = decMontlyFee.ToString("c")
        lblTotalFee.Text = decTotalFee.ToString("c")

    End Sub
End Class

2 个答案:

答案 0 :(得分:2)

您将需要读取 intMonths 的值,因为它仅是声明的,没有分配。

答案 1 :(得分:0)

intMonths分配给TextBox值。简化语法。

Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    Dim decMontlyFee As Decimal
    Dim decTotalFee As Decimal
    Dim intMonths As Integer = Integer.Parse(txtMonths.Text)
    Dim decAdultFee As Decimal = 40
    Dim decChildFee As Decimal = 20
    Dim decStudentFee As Decimal = 25
    Dim decSeniorFee As Decimal = 30
    Dim decYogaFee As Decimal = 10
    Dim decKarateFee As Decimal = 30
    Dim decTrainerFee As Decimal = 50
    decMontlyFee = If(radAdult.Checked, decAdultFee, decMontlyFee)
    decMontlyFee = If(radChild.Checked, decChildFee, decMontlyFee)
    decMontlyFee = If(radStudent.Checked, decStudentFee, decMontlyFee)
    decMontlyFee = If(radSenior.Checked, decSeniorFee, decMontlyFee)
    decMontlyFee += If(chkYoga.Checked, decYogaFee, 0)
    decMontlyFee += If(chkTrainer.Checked, decTrainerFee, 0)
    decMontlyFee += If(chkKarate.Checked, decKarateFee, 0)
    Select Case intMonths
        Case Is <= 3
            decMontlyFee *= 1
        Case 4 To 6
            decMontlyFee *= 0.95
        Case 7 To 9
            decMontlyFee *= 0.92
        Case Is >= 10
            decMontlyFee *= 0.9
    End Select
    decTotalFee = decMontlyFee * intMonths
    lblMonthlyFee.Text = decMontlyFee.ToString("c")
    lblTotalFee.Text = decTotalFee.ToString("c")
End Sub