编写程序,随机生成100个两位整数,并统计出其中小于等于40、大于40小于等于70、大于70的数据个数。
我写的是这样,为什么不可以??
Private Sub Form_Load()
Dim a As Integer, b As Integer, c As Integer, d As Integer
Do
d = Int(Rnd * (99 - 10) + 10)
If d <= 40 Then
a = a + 1
ifelse d > 40 And d <= 70
b = b + 1
ifelse d > 70
c = c + 1
End If
Loop Until a + b + c = 100
Print "<=40"; a
Print ">40and<=70"; b
Print ">70"; c
End Sub
參考答案:Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer, d As Integer
Randomize'随机种子
Do
d = Int(Rnd * (99 - 10) + 10)
If d <= 40 Then
a = a + 1
ElseIf d > 40 And d <= 70 Then'modifyed
b = b + 1
ElseIf d > 70 Then'modifyed
c = c + 1
End If
Loop Until a + b + c = 100
Print "<=40"; a
Print ">40and<=70"; b
Print ">70"; c
End Sub