Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: hellninjas on January 30, 2012, 11:58:13 pm

Title: String == Stringand some more questions...
Post by: hellninjas on January 30, 2012, 11:58:13 pm
How would I do...
If (/*USER INPUT*/) = "Suicide" :Disp "You Died" ???
This has been troublesome to me...
Also is there any more variables I can use instead of just a-z?
Like if I could do...  HOLY->235
or something...
Thanks :D/me just realized he hasn't done basic in a while!
I'm glad to be back :D!!
Title: Re: String == Stringand some more questions...
Post by: thydowulays on January 31, 2012, 12:03:43 am
This is BASIC correct?
You would do:
Code: [Select]
Input "",Str1
If Str1 = "SUICIDE":Disp "You Died"
Title: Re: String == Stringand some more questions...
Post by: hellninjas on January 31, 2012, 12:08:05 am
Code: [Select]
Input "",Str1
If Str1 = "SUICIDE":Disp "You Died"
else :Disp "Incorrect command"

Could this work?
Title: Re: String == Stringand some more questions...
Post by: thydowulays on January 31, 2012, 12:13:26 am
Yeah, that should work, sorry for the late reply
Title: Re: String == Stringand some more questions...
Post by: Hayleia on January 31, 2012, 12:48:18 am
Code: [Select]
Input "",Str1
If Str1 = "SUICIDE":Disp "You Died"
else :Disp "Incorrect command"

Could this work?
Nope. If you are using an Else, Then you need a Then then an End.

A correct (non optimized) code would be

Code: [Select]
Input "",Str1
If Str1="SUICIDE"
Then
Disp "You Died"
Else
Disp "Incorrect command"
End

And an optimized code would be

Code: [Select]
Input "",Str1
"Incorrect command"
If Str1="SUICIDE":"You Died"
Disp Ans
Title: Re: String == Stringand some more questions...
Post by: JosJuice on January 31, 2012, 12:42:54 pm
And an optimized code would be

Code: [Select]
Input "",Str1
"Incorrect command"
If Str1="SUICIDE":"You Died"
Disp Ans
More optimized!
Code: [Select]
Input "",Str1
"Incorrect command
If Str1="SUICIDE
"You Died
Disp Ans
The strings could be changed to uppercase, but that would change the output.