用VB实现猜商品价格游戏程序。
答案:2 悬赏:50 手机版
解决时间 2021-03-19 06:20
- 提问者网友:斑駁影
- 2021-03-18 20:48
用VB实现猜商品价格游戏程序。
最佳答案
- 五星知识达人网友:十鸦
- 2021-03-18 21:44
Private Sub Command1_Click()
Randomize Timer
Dim jg As Integer, c As Integer, n As Integer
jg = Int(Rnd * 1001)
Do
n = Val(InputBox("请输入商品价格0~1000:"))
c = c + 1
Select Case n
Case -1
Case Is > jg
MsgBox "高了,放弃请输入-1"
Case Is < jg
MsgBox "低了,放弃请输入-1"
End Select
Loop While jg <> n And n <> -1
If n = -1 Then
MsgBox "已经放弃"
Else
MsgBox "价格是:" & jg & ",猜的次数:" & c
End If
End Sub
Randomize Timer
Dim jg As Integer, c As Integer, n As Integer
jg = Int(Rnd * 1001)
Do
n = Val(InputBox("请输入商品价格0~1000:"))
c = c + 1
Select Case n
Case -1
Case Is > jg
MsgBox "高了,放弃请输入-1"
Case Is < jg
MsgBox "低了,放弃请输入-1"
End Select
Loop While jg <> n And n <> -1
If n = -1 Then
MsgBox "已经放弃"
Else
MsgBox "价格是:" & jg & ",猜的次数:" & c
End If
End Sub
全部回答
- 1楼网友:老鼠爱大米
- 2021-03-18 22:58
'在窗体上画一个按钮,名称可用默认值“Command1”,Caption属性设为“开始”,复制以下代码:
private sub Command1_Click()
dim R as long
dim S as long ,sInput as string
dim sPrompt as string
dim iTimes as long
randomize timer
R=clng(rnd()*1000) '若不包括0和1000,须改成R=1+int(rnd()*999)
do
iTimes=iTimes+1
sInput=inputbox(sPrompt & "请输入第" & iTimes & "次所猜的价格:")
if isnumeric(sInput) then
S=val(sInput)
if S>R then sPrompt="‘" & S & "元’高了,"
if S if S=R then msgbox "‘" & S & "元’猜对了!!成绩为" & iTimes & "次!",vbInformation :exit sub
else
msgbox "您放弃了游戏,正确价格应该是:" & R & "元" :exit sub
end if
loop
end sub
private sub Command1_Click()
dim R as long
dim S as long ,sInput as string
dim sPrompt as string
dim iTimes as long
randomize timer
R=clng(rnd()*1000) '若不包括0和1000,须改成R=1+int(rnd()*999)
do
iTimes=iTimes+1
sInput=inputbox(sPrompt & "请输入第" & iTimes & "次所猜的价格:")
if isnumeric(sInput) then
S=val(sInput)
if S>R then sPrompt="‘" & S & "元’高了,"
if S
else
msgbox "您放弃了游戏,正确价格应该是:" & R & "元" :exit sub
end if
loop
end sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯