如何增加计算程序的最高分

时间:2019-04-30 12:58:56

标签: vba visual-studio visual-studio-2017 windows-forms-designer

我写代码来计算学校的分数。当学生的总成绩达到68分以下时,他们将有机会获得红利分数。奖金分数可以选择三个选项。但是,加上奖金后,总分不能超过68分。我应该如何完成最后一部分?

这是我编写的代码

        If result < 68 Then
            If RadioButton1.Checked = True Then
                bonus = 15.0
            End If
            If RadioButton2.Checked = True Then
                bonus = 10.0
            End If
            If RadioButton3.Checked = True Then
                bonus = 5.0
            End If
        End If

        total = result + bonus

1 个答案:

答案 0 :(得分:0)

  1. 我认为您应该保留有关是否添加奖金的信息

        Dim IsBonusAdded As Boolean
        IsBonusAdded = False
        If result < 68 Then
            If RadioButton1.Checked = True Then
                bonus = bonus
                IsBonusAdded = True
            End If
            If RadioButton2.Checked = True Then
                bonus = 10.0
                IsBonusAdded = True
            End If
            If RadioButton3.Checked = True Then
                bonus = 5.0
                IsBonusAdded = True
            End If
        End If
    
        total = result + bonus
        ' total can't be more than 68 if bonus added
        If IsBonusAdded And total >=68 Then
             total = 68
        End If
    
  2. 是否必须多次添加奖金?然后您应该更正代码

        Dim IsBonusAdded As Boolean
        If result < 68 Then
            If RadioButton1.Checked = True Then
                bonus = bonus + 15
                IsBonusAdded = True
            End If
            If RadioButton2.Checked = True Then
                bonus = bonus + 10
                IsBonusAdded = True
            End If
            If RadioButton3.Checked = True Then
                bonus = bonus + 5
                IsBonusAdded = True
            End If
        End If
    
        total = result + bonus
        ' total can't be more than 68 if bonus added
        If IsBonusAdded And total >68 Then
             total = 68
        End If