卡在VbScript上 [英] stuck on VbScript
问题描述
这是我可以使用的代码,但是问题是当它运行时,如果输入6来猜测它表示它太高,您将得到55.00的数字.我缺少将单个数字与双Didget数进行比较的功能吗?
'初始化部分
选项显式
dim intUsernumber,intrandomnum ,stroktoend,intnumguess
const cGreetingmsg =选择1到100之间的数字"
intnumguess = 0
'生成随机数
randomize
intrandomnum = formatnumber(int((rnd * 100)+1))
msgbox intrandomnum
'循环直到其中一个用户正确猜测或单击cancle按钮,直到stroktoend =是"
'提示用户t选择一个数字
intusernumber = inputbox(输入您的猜测:" ;,cGreetingmsg)
intnumguess = intnumguess +1
'看看用户是否提供了答案
如果len(intusernumber)<> 0,然后
'确保用户键入了一个数字
,如果IsNumeric(intusernumber)= true,则
'测试以查看用户是否猜出了正确的数字
如果formatnumber(intusernumber)= intrandomnum,则
msgbox"恭喜您猜对了.这个数字是"&使用者编号& ." & vbcrlf& vbcrlf& "您在"中猜到了&诚信" guesses" ;, cGreetingmsg
stroktoend ="yes"
end if
'测试以查看用户的猜测是否太低
if formatnumber(intusernumber )<然后进行intrandomnum
msgbox"您的猜测太低了.再试一次,,cGreetingmsg
stroktoend ="否"
if if
'测试用户是否猜得太高了
if formatnumber(intusernumber)> ; (intrandomnum)然后
msgbox您的猜测太高了.再试一次",cGreetingmsg
stroktoend =否"
msgbox(intusernumber)& " :" & intrandomnum
if
结束
else
msgbox"抱歉,您没有输入数字.再试一次",,cGreetingmsg
,如果
else
msgbox结束,您输入值失败或单击cancle.请稍后再玩!" ,,ccreetingmsg
stroktoend ="yes"
如果
循环
here is te code i have that does work but the problem is when it runs you get a number of say 55.00 if you enter 6 for a guess it says it is too high. what am i missing to have it compare a single number to a double didget number?
'initialization section
option explicit
dim intUsernumber, intrandomnum, stroktoend, intnumguess
const cGreetingmsg = "Pick a number between 1 - 100"
intnumguess = 0
'generate a random number
randomize
intrandomnum = formatnumber(int((rnd*100)+1))
msgbox intrandomnum
'loop untill either the user guesses correctly or clicks the cancle button
do until stroktoend = "yes"
'prompt user t pick a number
intusernumber = inputbox("Type your guess: ", cGreetingmsg)
intnumguess = intnumguess +1
'see if user provided an answer
if len(intusernumber) <> 0 then
'make sure the user typed a number
if IsNumeric(intusernumber) = true then
'test to see if the user guessed the correct number
if formatnumber(intusernumber) = intrandomnum then
msgbox "Congratulations you guessed it. The number was " & intusernumber & "." & vbcrlf & vbcrlf & "You guessed it in " & intnumguess & "guesses", , cGreetingmsg
stroktoend = "yes"
end if
'test to see if the user guess was too low
if formatnumber(intusernumber) < intrandomnum then
msgbox "Your guess was too low. Try again", ,cGreetingmsg
stroktoend = "no"
end if
'test to see if the user guessed too high
if formatnumber(intusernumber) > (intrandomnum) then
msgbox "Your guess was too high. Try again", ,cGreetingmsg
stroktoend = "no"
msgbox (intusernumber) & " : " & intrandomnum
end if
else
msgbox " Sorry you did not enter a number. Try again", , cGreetingmsg
end if
else
msgbox "You either failed to type a value or you click on cancle. Please play again soon!" , ,cGreetingmsg
stroktoend = "yes"
end if
loop
推荐答案
尝试一下.问题在于您的代码仅评估了第一个整数,因此,如果您拥有数字57并键入6,它将太高,但是如果您键入4则将其降到低,并且如果您键入5,则它将对第二个整数进行求值数字.因此,我删除了所有'Formatnumber'实例,删除了len()以使您的取消生效,并使inputbox()返回一个整数.看来对我有用.
'initialization section
option explicit
dim intUsernumber, intUsernumber1, intrandomnum, stroktoend, intnumguess
const cGreetingmsg = "Pick a number between 1 - 100"
intnumguess = 0
'generate a random number
randomize
intrandomnum = Int(100 * rnd())
msgbox intrandomnum
'loop untill either the user guesses correctly or clicks the cancle button
do until stroktoend = "yes"
'prompt user t pick a number
intusernumber = Int(inputbox("Type your guess: ", cGreetingmsg))
intnumguess = intnumguess +1
'see if user provided an answer
if intusernumber <> 0 then
'make sure the user typed a number
if IsNumeric(intusernumber) = true then
'test to see if the user guessed the correct number
if intusernumber = intrandomnum Then
msgbox "Congratulations you guessed it. The number was " & intusernumber & "." & vbcrlf & vbcrlf & "You guessed it in " & intnumguess & " guesses", , cGreetingmsg
stroktoend = "yes"
end if
'test to see if the user guess was too low
if intusernumber < intrandomnum then
msgbox "Your guess was too low. Try again", ,cGreetingmsg
stroktoend = "no"
end if
'test to see if the user guessed too high
if intusernumber > intrandomnum then
msgbox "Your guess was too high. Try again", ,cGreetingmsg
stroktoend = "no"
msgbox intusernumber & " : " & intrandomnum
end if
else
msgbox " Sorry you did not enter a number. Try again", , cGreetingmsg
end if
else
msgbox "You either failed to type a value or you click on cancel. Please play again soon!" , ,cGreetingmsg
stroktoend = "yes"
end if
loop
这篇关于卡在VbScript上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!