Public Class Form1
Private Sub cmdmark_Click(sender As Object, e As EventArgs) Handles cmdmark.Click
Dim intsum As Integer, intnum As Integer
Dim inthighest As Integer
Dim intlowest As Integer
intnum = InputBox("Enter the mark")
intsum = intnum + intsum
intnum = InputBox("Enter the mark For subject 2")
intsum = intnum + intsum
intnum = InputBox("Enter the mark for subject 3")
intsum = intnum + intsum
Lbltotal.Text = "Total marks are" & intsum
lblaverage.Text = "The average is" & intsum / 3
If intnum > intlowest Then
intlowest = intsum
End If
If intsum > inthighest Then
inthighest = intsum
Lbllowest.Text = "The lowest number is" & intnum
Lblhighest.Text = "The highets number is" & intnum
End If
End Sub
End Class
基本上,当我添加我的三个标记时,它确实有效,但它没有显示最低标记,而是显示与标记最高的标记相同
答案 0 :(得分:1)
Lbllowest.Text = "The lowest number is" & intnum
和
Lblhighest.Text = "The highets number is" & intnum
是相同的整数,是1显示相同值的原因。
也许尝试使用3个单独的整数,Mark1_Integer,Mark2_Integer,Mark3_Integer。您可以更轻松地找到您的高低。
答案 1 :(得分:1)
您应该在每次输入后计算最低值和最高值:
intnum = InputBox("Enter the mark")
intsum = intsum
intlowest = intsum
inthighest = intsum
intnum = InputBox("Enter the mark For subject 2")
intsum = intnum + intsum
If intnum < intlowest Then
intlowest = intnum
End If
If intsum > inthighest Then
inthighest = intnum
End If
intnum = InputBox("Enter the mark for subject 3")
intsum = intnum + intsum
If intnum < intlowest Then
intlowest = intnum
End If
If intsum > inthighest Then
inthighest = intnum
End If
Lbllowest.Text = "The lowest number is" & intlowest
Lblhighest.Text = "The highets number is" & inthighest
在这段代码中还有很多可以改进的地方,例如将隐式转换更改为显式转换并将代码重构重构为方法,但这应该可以帮助您开始。
答案 2 :(得分:0)
我对Python知之甚少,但我认为你可以试过
If intnum >= intlowest Then
intlowest = intsum
或
If intnum == intlowest Then
intlowest = intsum
但实际上我从ace writers学到的是你应该经常测试并测试它,尝试不同的组合直到它起作用。