Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IF THEN Command
#1
Hey i'v read ur tutorials! they're really helpfull!

I understand the IF something = something THEN something command!!

but what if it isn't something! Let me explain!!!

PRINT "Does 2 + 2 = 4 ?"
INPUT answer$
IF answer$ = "yes" THEN PRINT "correct"
IF answer$ = "no" THEN PRINT "incorrect"
END

But what if they were to type in "oogibabble" instead of yes or no? it just conrinues! how can i tell it to go back and ask again if they don't type yes or no??

Please help!
Tom. if u want to e-mail me it's tomlewis86@hotmail.com
Reply
#2
ELSE

Or just use GOTO after the answer.

Or select.

I didn't know about ELSE for a long time, actually..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
Code:
PRINT "Does 2 + 2 = 4 ?"
INPUT answer$
IF answer$ = "yes" THEN PRINT "correct"
IF answer$ = "no" THEN PRINT "incorrect"
END

I do it like this

Code:
PRINT "Does 2 + 2 = 4 ?"
redo:
INPUT answer$
SELECT CASE answer$
CASE "yes"
  PRINT "correct"
CASE "no"
  PRINT "incorrect"
CASE ELSE
  GOTO redo
END SELECT
END

Or


Code:
PRINT "Does 2 + 2 = 4 ?"
redo:
INPUT answer$
IF answer$ = "yes" THEN
PRINT "correct"
ELSEIF answer$ = "no" THEN
PRINT "incorrect"
ELSE
GOTO redo
END IF
END
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#4
Code:
IF 2 + 2 = 4 THEN PRINT "true"
IF 2 + 2 <> 4 THEN PRINT "false"
IF "hey" = "hey" THEN PRINT "true"
IF "hey" = "aye" THEN PRINT "false"
IF "hey" <> "aye" THEN PRINT "true"
IF "hey" <> "hey" THEN PRINT "false"
earn.
Reply
#5
I would do like this :

PRINT "Does 2+2=4"

redo:
INPUT answer$
IF answer$<>("yes" or "YES") THEN PRINT "FALSE" : GOTO REDO
PRINT "TRUE"

END
have the simplest tastes of the World : I satisfy myself with the best !

http://ToufQb.free.fr
Reply
#6
Sorry , I made a huge mistake .
This one will work perfectly :

PRINT "Does 2+2=4"

redo:
INPUT answer$
IF answer$<>"yes" or answer$<>"YES" THEN PRINT "FALSE" : GOTO REDO
PRINT "TRUE"

END
have the simplest tastes of the World : I satisfy myself with the best !

http://ToufQb.free.fr
Reply
#7
Quote:This one will work perfectly

Not quite.

Code:
PRINT "Does 2+2=4"

redo:
INPUT answer$
IF LCASE$(answer$) <> "yes" THEN PRINT "FALSE" : GOTO REDO
PRINT "TRUE"

END
earn.
Reply
#8
Code:
DIM SHARED choice.amount AS INTEGER
choice.amount = 2
DIM SHARED choice.string$(0 TO choice.amount)
DIM SHARED choice.color(0 TO choice.amount) AS INTEGER
DIM SHARED len.choice(0 TO choice.amount) AS INTEGER, max.len.choice AS INTEGER
DIM SHARED thequestion$, len.thequestion.plus.two AS INTEGER
thequestion$ = "Is 2 + 2 = 4?"
choice.string$(0) = "I don't know!"
choice.string$(1) = "Yes"
choice.string$(2) = "No"
choice.color%(0) = 9
choice.color%(1) = 2
choice.color%(2) = 4
len.thequestion.plus.two = LEN(thequestion$) + 2


FOR I% = 0 TO choice.amount% - 1
temp% = LEN(choice.string$(I%))
IF temp% > max.len.choice% THEN max.len.choice% = temp%
len.choice%(I%) = temp%
NEXT I%
SCREEN 7: CLS
LOCATE 1, 1: PRINT thequestion$
I% = 0
DO
DO: I$ = INKEY$: LOOP UNTIL I$ <> ""
SELECT CASE I$
CASE CHR$(0) + "M", CHR$(0) + "P": I% = I% + 1: IF I% > choice.amount% THEN I% = 0
CASE CHR$(0) + "K", CHR$(0) + "H": I% = I% - 1: IF I% < 0 THEN I% = choice.amount%
CASE CHR$(13): EXIT DO
END SELECT

COLOR choice.color%(I%)
LOCATE 1, len.thequestion.plus.two
PRINT choice.string$(I%) + STRING$(max.len.choice% - len.choice%(I%), " ")
LOOP

              
IF I% = 1 THEN
FOR I% = 1 TO 200
SOUND 37 + .5 * I% ^ 2, .05
NEXT I%
LOCATE 13, 5
right1$ = "That's right! 2+2=4! Yessir!"
len.right% = LEN(right1$)
c% = 1
FOR I% = 1 TO len.right%
IF c% < 15 THEN c% = c% + 1 ELSE c% = 1
COLOR c%
PRINT MID$(right1$, I%, 1);
NEXT I%
SLEEP 1
LOCATE 20, 1
COLOR 14: PRINT "Please press the officially designated  <any key> to continue.";
SLEEP
LOCATE 22, 4:
COLOR 2: PRINT "Any key: pround sponsor of this Useless Program.";
SLEEP
ELSE
col1% = 4
col2% = 12
col3% = 14
col4% = 15
PRINT
DO
COLOR col1%
PRINT "WRONG!";
columns% = columns% + 1
IF columns% = 6 THEN
columns% = 0
t2% = t2% + 1
IF t2% = 4 THEN
t2% = 0
SWAP col1%, col2%
SWAP col1%, col3%
SWAP col1%, col4%
END IF
PRINT
END IF
IF INKEY$ <> "" THEN
EXIT DO
CLS
LOCATE 13, 16
COLOR 4
PRINT "W-R-O-N-G!"
SLEEP
EXIT DO
END IF
LOOP
END IF
SYSTEM
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#9
lol :rotfl:
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#10
Code:
DO
   PRINT "Does 2 + 2 = 4 ?"
   INPUT answer$
LOOP UNTIL LCASE$(answer$) = "yes" OR LCASE$(answer$) = "no"
IF answer$ = "yes" THEN PRINT "correct"
IF answer$ = "no" THEN PRINT "incorrect"
END
Is another way...
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][Image: safer.gif][/url]
END OF LINE.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)