嘉兴长安镇:帮忙看一道vbscript题目

来源:百度文库 编辑:神马品牌网 时间:2024/05/06 05:43:45
页面功能:程序随机产生一个100以内的整数,用户通过输入框猜测数的大小,如果输入的数比起始的随机数大则提示用户输入的数太大,如果输入的数比起始的随机数小则提示用户输入的数太小,并重新要求用户输入新的数,直到猜对;猜对了则提示用户“猜中了”。
编写程序时,使用num变量存放随机数,ans变量存放猜测的数。

用vbscript!

<script language="vbscript">
do
Randomize
num=Int(100 * Rnd )
ans=inputbox("请输入100以内的整数")
if ans>num then
msgbox("您的输入太大")
end if
if ans<num then
msgbox("您的输入太小")
end if
if ans=num then
msgbox("猜对了")
exit do
end if
loop
</script>

do '另存为guess.vbs
Randomize
num=Int(100 * Rnd )
msgbox num
do
ans=cint(inputbox("请输入100以内的整数"))

if ans=0 then msgbox "退出" : wscript.quit

if ans>num then
msgbox("您的输入太大,继续努力")
else
if ans<num then
msgbox("您的输入太小,继续努力哦")
else
if ans=num then
msgbox("恭喜你,猜对了!")
exit do
end if
end if
end if
loop
loop