四则运算测试:每次运行,只能做十道题,题目通过产生随机数组成的两位数的四则运算式组成,

问题描述:

四则运算测试:每次运行,只能做十道题,题目通过产生随机数组成的两位数的四则运算式组成,
若是除法,四舍五入,保留小数点后两位

Private Sub Command1_Click()
Dim i As Integer,k As Integer,s As Long,s1 As Double
Dim a As Integer,b As Integer,ab As String
i = 0
Randomize
a = Int(Rnd() * 99) + 30
Randomize
b = Int(Rnd() * 99) + 30
Randomize
k = Int(Rnd() * 10) + 1
s = 0
s1 = 0
If i > 10 Then
MsgBox "Sorry,每次只能运算10题!"
Exit Sub
End If
If k ab = "+"
s = a + b
Else
If k ab = "-"
s = a - b
Else
If k ab = "*"
s = a * b
Else
ab = "/"
s1 = a / b
s1 = Format(s1,"0.00")
End If
End If
End If
If ab = "/" Then
Label1.Caption = a & " " & ab & " " & b & " = " & s1
i = i + 1
Else
Label1.Caption = a & " " & ab & " " & b & " = " & s
i = i + 1
End If
End Sub