|
How to
Jun 13, 2005 2:47:37 GMT
Post by Edwin on Jun 13, 2005 2:47:37 GMT
I want to learn how to do a message loop where I ask a question, if its write a messege appears, end of program, but if incorrect it gives a clue and re-asks the question. here is what I want to work. cls input "D'you know the capital of Alaska?", names$ select case names$ case "Juneau" print " that's correct" case else print "It rhymes with D'you know" end select end I'm I using the wrong format?
|
|
buff1
New Member
Posts: 3
|
How to
Jun 13, 2005 4:26:42 GMT
Post by buff1 on Jun 13, 2005 4:26:42 GMT
...if it's write.... s/b ...if it's right...
anyway. #1 make the names$ upper case (or lower case) names$=ucase$(names$)
#2 if they get it correct then put OK%=1
cls 10 OK%=0 input "D'you know the capital of Alaska?", names$ names$=UCASE$(names$) select case names$ case "JUNEAU" print " that's correct" OK%=1 case else print "It rhymes with D'you know" OK%=0 end select IF NOT OK% THEN GOTO 10 end
quick fix.
|
|
buff1
New Member
Posts: 3
|
How to
Jun 13, 2005 4:28:42 GMT
Post by buff1 on Jun 13, 2005 4:28:42 GMT
The code tag didnt indent so i'll do it this way. cls 10 OK%=0 input "D'you know the capital of Alaska?", names$ names$=UCASE$(names$) select case names$ case "JUNEAU" print " that's correct" OK%=1 case else print "It rhymes with D'you know" OK%=0 end select IF NOT OK% THEN GOTO 10 end
|
|
|
How to
Jun 13, 2005 10:27:23 GMT
Post by Ildûrest on Jun 13, 2005 10:27:23 GMT
Sorry buff, your code won't work. (NOT 1) is nonzero, that is, it's treated as true. If you change OK% = 1 to OK% = -1 it should work.
However I don't really like using sentinel variables. Anyway, here's a nice clean way to do it that uses a DO-LOOP rather than a GOTO:
CLS
DO INPUT "D'you know the capital of Alaska? ", names$
IF UCASE$(names$) = "JUNEAU" THEN EXIT DO
PRINT "(It rhymes with D'you know)" LOOP
PRINT "That's correct."
END
Notes: -UCASE$() returns a string with any letters converted to uppercase. Just an added option to make it easier for the user. -EXIT DO obviously makes the program leave the current DO-LOOP. -Please take a moment to work out how the program works. The logic is not completely obvious, but being able to come up with methods like this is very helpful in programming.
Good luck!
Ildûrest
|
|
buff1
New Member
Posts: 3
|
How to
Jun 14, 2005 19:40:42 GMT
Post by buff1 on Jun 14, 2005 19:40:42 GMT
OK well then you could use If OK% then END GOTO 10
|
|
|
How to
Jun 14, 2005 19:46:31 GMT
Post by Buff1 on Jun 14, 2005 19:46:31 GMT
Or avoiding GOTO statements OK%=0 WHILE OK%=0 Line input "D'you know the capital of Alaska?", names$ names$=UCASE$(names$) select case names$ case "JUNEAU" print " that's correct" OK%=1 case else print "It rhymes with D'you know" OK%=0 end select WEND
|
|