请教一个vb编程题,请大家帮忙,不胜感激!
今天老师出了一道VB编程题,题是这样的:猜数:A表示数猜对了而且位数也对,B表示数猜对了但位数不对例如:出题者出的数是1234,而猜题者猜的是3456,系统则提出“2B”...
今天老师出了一道VB编程题,题是这样的:
猜数:
A 表示数猜对了而且位数也对,B 表示数猜对了但位数不对
例如:出题者出的数是1234,而猜题者猜的是3456,系统则提出“2B”
出题者出的数是1234,而猜题者猜的是4231,系统则提出“2A2B”
程序要求是这样的:程序运行——输入一个4位数(由出题者给出)——猜数者输入自己猜的数——程序判断并给出几A几B的提示,若对就提示“恭喜您回答正确”若不对则继续猜,直至猜对为止
请各位高手不吝赐教,我是一菜鸟,老师留的这道题关系到成绩,请大家帮忙! 展开
猜数:
A 表示数猜对了而且位数也对,B 表示数猜对了但位数不对
例如:出题者出的数是1234,而猜题者猜的是3456,系统则提出“2B”
出题者出的数是1234,而猜题者猜的是4231,系统则提出“2A2B”
程序要求是这样的:程序运行——输入一个4位数(由出题者给出)——猜数者输入自己猜的数——程序判断并给出几A几B的提示,若对就提示“恭喜您回答正确”若不对则继续猜,直至猜对为止
请各位高手不吝赐教,我是一菜鸟,老师留的这道题关系到成绩,请大家帮忙! 展开
展开全部
Dim strA As String, strB As String
Dim x(4) As Integer, y(4) As Integer
Dim A As Integer, B As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer
strA = Trim(Text1.Text)
strB = Trim(Text2.Text)
A = 0
B = 0
If Len(strB) = 4 Then
For i = 1 To 4
x(i) = Mid(strB, i, 1)
If x(i) = y(i) Then
A = A + 1
End If
For j = 1 To 4
If x(i) = y(j) Then
B = B + 1
End If
Next
Next
End If
Label1.Caption = A & "A" & (B - A) & "B"
If A = 4 Then
MsgBox "恭喜你回答正确!", , "正确"
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
A = 0
B = 0
For i = 1 To 4
Randomize
l:
y(i) = Int(9 * Rnd)
If y(1) = 0 Then GoTo l
For j = 1 To i - 1
If y(j) = y(i) Then GoTo l
Next j
Next i
Text1.Text = y(1) & y(2) & y(3) & y(4)
End Sub
用到的控件:1个按钮,2个textbox,1个label
烂掉の萝卜
为你,我追逐落日!
网站: http://www.luobo528.com/
论坛: http://bbs.luobo528.com/
Dim x(4) As Integer, y(4) As Integer
Dim A As Integer, B As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer
strA = Trim(Text1.Text)
strB = Trim(Text2.Text)
A = 0
B = 0
If Len(strB) = 4 Then
For i = 1 To 4
x(i) = Mid(strB, i, 1)
If x(i) = y(i) Then
A = A + 1
End If
For j = 1 To 4
If x(i) = y(j) Then
B = B + 1
End If
Next
Next
End If
Label1.Caption = A & "A" & (B - A) & "B"
If A = 4 Then
MsgBox "恭喜你回答正确!", , "正确"
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
A = 0
B = 0
For i = 1 To 4
Randomize
l:
y(i) = Int(9 * Rnd)
If y(1) = 0 Then GoTo l
For j = 1 To i - 1
If y(j) = y(i) Then GoTo l
Next j
Next i
Text1.Text = y(1) & y(2) & y(3) & y(4)
End Sub
用到的控件:1个按钮,2个textbox,1个label
烂掉の萝卜
为你,我追逐落日!
网站: http://www.luobo528.com/
论坛: http://bbs.luobo528.com/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询