[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
答案 0 :(得分: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 ...那么... ELSE句子在打印后结束,随后GOTO将在任何一种情况下运行。
在大多数BASIC中,您可以这样做:
IF g > n THEN
PRINT "Your guess was wrong. Try again! The correct answer was "; n;".";
ELSE
GOTO Start
END IF
但我不确定你的风味。
答案 1 :(得分: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