[Start]
n=INT((RND*10)+1)
PRINT "I have thought of a number."
PRINT "Try to guess it!"
PRINT "Enter your guess."
INPUT g
[Right]
IF g=n THEN GOTO [Finish]
**IF g < n PRINT "Your guess was wrong. Try again. The correct answer was "; n;"." THEN GOTO [Start]
IF g > n PRINT "Your guess was wrong. Try again! The correct answer was "; n;"." THEN GOTO [Start]**
[Finish]
PRINT "Well done! You guessed it."
END
问问题
88 次
2 回答
0
IF condition THEN positive ELSE negative
然而,这
IF g > n THEN PRINT "Your guess was wrong. Try again! The correct answer was "; n;"."; GOTO [Start]
不会做你想做的,因为 IF...THEN...ELSE 语句在打印之后结束,随后的 GOTO 将在任何一种情况下运行。
在大多数 BASIC 中,您可以这样做:
IF g > n THEN
PRINT "Your guess was wrong. Try again! The correct answer was "; n;".";
ELSE
GOTO Start
END IF
但我不确定你的特殊口味。
于 2013-07-12T09:59:20.170 回答
0
虽然它可以用更少的 GOTO 来编写,但这也应该有效:
[Start]
n=INT((RND*10)+1)
PRINT "I have thought of a number."
PRINT "Try to guess it!"
PRINT "Enter your guess."
INPUT g
[Right]
IF g=n THEN GOTO [Finish]
PRINT "Your guess was wrong. Try again. The correct answer was "; n;"."
GOTO [Start]
[Finish]
PRINT "Well done! You guessed it."
END
于 2015-11-30T16:03:41.110 回答