我写代码来计算学校的分数。当学生的总成绩达到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
答案 0 :(得分:0)
我认为您应该保留有关是否添加奖金的信息
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
是否必须多次添加奖金?然后您应该更正代码
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