如何为计算程序添加最高分数

问题描述 投票:0回答:1

我为学校的分数计算编写代码。当学生总得分低于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
vba visual-studio visual-studio-2017 windows-forms-designer
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.