3

I'm trying to display text based on a user's input. For example inputting the word APPLE should make it display BANANA.

This snippet works fine:

:Input X
:If X=APPLE
:Disp "BANANA"

But I'm unsure how to build off this to make a series of checks:

:Input X
:If X=Apple
:Disp "BANANA"
:If X=LEMON
:Disp "LIME"
:If X=PEACH
:Disp "PEAR"

If I do this, it displays BANANA, LIME, and PEAR in that order regardless of what I actually input. What am I missing?

4444
  • 3,541
  • 10
  • 32
  • 43

2 Answers2

2

Try rewriting your snippet to use Str1 instead of X. This will ensure you're comparing a string type to a another string type.

:Input Str1

:If Str1="APPLE"
:Then
:Disp "BANANA"
:End

:If Str1="LEMON"
:Then
:Disp "LIME"
:End

:If Str1="PEACH"
:Then
:Disp "PEAR"
:End
4444
  • 3,541
  • 10
  • 32
  • 43
0

The accepted answer is correct, but it is using unnecessary Then/End statements and end quotes for a total of 18 bytes extra. I'd recommend this code which is more similar to your original:

Input Str1
If Str1="APPLE
Disp "BANANA
If Str1="LEMON
Disp "LIME
If Str1="PEACH
Disp "PEAR

Assuming the above code is an entire program, it can be shortened to:

Input Str1
If Str1="APPLE    <-- you can remove this line if you know there will be no invalid input
"BANANA
If Str1="LEMON
"LIME
If Str1="PEACH
"PEAR
Ans
Timtech
  • 1,224
  • 2
  • 19
  • 30