vb求一个猜数字游戏的代码?

2025-02-26 13:12:59
推荐回答(1个)
回答1:

Dim a As Integer
        a = Int(Rnd() * 100)
        Dim n As Integer
        n = 0
        Dim m As Integer
        m = 1
        TextBox1.Text = a
        Do
            n = InputBox("第" & m & "次了,请猜")
            If n > a Then
                MsgBox("太大了")
            ElseIf n < a Then
                MsgBox("太小了")
            Else
                MsgBox("猜对了")
            End If
            m = m + 1
            If m > 10 Then
                MsgBox("没猜对")
                Exit Do
            End If
        Loop Until a = n