Search code examples
calculatorti-basic

If Then statement displays all possibilites


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?


Solution

  • 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