基本上我试图创建一个.vbs文件,它会给你带来十个随机添加问题。然后,在输入框中,键入给定问题的答案。一切都有效,但If
/ Else
声明会告诉您是对还是错。如果它说"什么是2 + 2"我打字#34; 4" (没有引用),然后它输出"(你攻击)TRIP! POW!你错了如果输入的话,你可以把它弄好:4。"这是代码:
msgbox("Starting addition. Press OK to begin.")
dim i
i = 0
Do
i = i + 1
'i is for the question timer
Dim max,min
max=100 'max random
min=1 'min random
dim j, k, l 'part part total
Randomize
msgbox("What is")
j = Int((max-min+1)*Rnd+min)
msgbox(j)
msgbox("plus")
k = Int((max-min+1)*Rnd+min)
msgbox(k)
answer = Inputbox("I hope you got all of that... ^_^")
l = j + k
if answer = l then
msgbox("(You attack) BAM! Right on target")
else
msgbox("(You attack) TRIP! POW! ouchy wrong")
msgbox("You could've gotten it right IF you typed:")
msgbox(l)
end if
loop until i = 10
答案 0 :(得分:1)
请参阅Comparison Operators (VBScript)参考:
...如何比较表达式或比较结果, 取决于潜在的子类型:
...
如果一个表达式是数字,另一个是字符串那么,数字表达式 字符串表达式。
j = Int((max-min+1)*Rnd+min)
k = Int((max-min+1)*Rnd+min)
answer = Inputbox("I hope you got all of that... ^_^" _
& vbCR & "What is " & j & " plus " & k)
l = j + k
If IsNumeric( answer) then
answer = Int( answer)
Else
answer = l - 1
End If
if answer = l then
msgbox("(You attack) BAM! Right on target")
else
msgbox("(You attack) TRIP! POW! ouchy wrong")
msgbox("You could've gotten it right IF you typed:")
msgbox(l)
end if