我在QBASIC中有一个IF声明......是的...... QBASIC ......
我一直在教别人编程(我觉得这很好看,也很容易看到 语法是如何工作的。)
......无论如何,我有这段代码:
CLS
start:
INPUT ">>", a$
PRINT a$
IF (INSTR(a$, "do you")) THEN
IF (INSTR(a$, "like")) THEN
IF (INSTR(a$, "cheese")) THEN PRINT "Yep, I like cheese":
IF (INSTR(a$, "music")) THEN PRINT "Depends, which genre?": GOTO musicGenre
ELSE IF (INSTR(a$, "hate")) THEN
IF (INSTR(a$, "cheese")) THEN PRINT "No, I like cheese"
END IF
END IF
END IF
musicGenre:
INPUT ">>", m$
SELECT CASE (m$)
CASE "pop"
PRINT "..pop! lol, baa baa"
CASE "rock"
PRINT "Rock is ok"
END SELECT
GOTO start
但是当我输入“do you like cheese?
”时,它似乎每隔一段时间才回复“Yep, I like cheese
”......
有人可以对此有所了解吗?
注意:
“do you like music?
”每时间
注2:
输出屏幕截图:
答案 0 :(得分:4)
您提供的代码显示正确。
请尝试以下方法之一:
a$
之前输出输入(IF
),以确认您的代码将使用预期的输入。FALSE
为零,其他为真。但是,您可能希望更明确地使用以下IF (INSTR(a$) > 0)
。 编辑:您应该在任何奶酪结果上加goto start
。否则,它将转到musicGenre
代码。
答案 1 :(得分:1)
CLS
start:
INPUT ">>", a$
IF (INSTR(1, a$, "do you")) THEN
IF (INSTR(1, a$, "like")) THEN
IF (INSTR(1, a$, "cheese")) THEN PRINT "Yep, I like cheese"
IF (INSTR(1, a$, "music")) THEN PRINT "Depends, which genre?": GOSUB musicGenre
END IF
IF (INSTR(1, a$, "hate")) THEN
IF (INSTR(1, a$, "cheese")) THEN PRINT "No, I like cheese"
END IF
END IF
GOTO start
musicGenre:
INPUT ">>", m$
SELECT CASE (m$)
CASE "pop"
PRINT "..pop! lol, baa baa"
CASE "rock"
PRINT "Rock is ok"
END SELECT
RETURN
答案 2 :(得分:0)
该程序演示了如何在Basic中解析输入和gosub。
REM Cheese progran source:
CLS
DO
INPUT ">>", a$
a$ = LCASE$(a$)
PRINT a$
IF INSTR(a$, "do you") THEN
IF INSTR(a$, "like") THEN
IF INSTR(a$, "cheese") THEN
PRINT "Yep, I like cheese":
END IF
IF INSTR(a$, "music") THEN
PRINT "Depends, which genre?"
GOSUB MusicGenre
END IF
ELSE
IF INSTR(a$, "hate") THEN
IF INSTR(a$, "cheese") THEN
PRINT "No, I like cheese"
END IF
END IF
END IF
END IF
LOOP
END
MusicGenre:
INPUT ">>>", m$
a$ = LCASE$(a$)
SELECT CASE (m$)
CASE "pop"
PRINT "..pop! lol, baa baa"
CASE "rock"
PRINT "Rock is ok"
END SELECT
RETURN