This is what the code looks like basically I want that when they enter A and B if A is greater then B it stops the program but for some reason It doesn't work so if I enter A=10 and B=1 it does not stop and just continues the rest of the code. However if I switch the 'If A>B' to 'If A<B' then no matter what I enter it stops the program. I really don't see what Im screwing up here


Code:
ClrHome
Disp "Number(?,?)
Input "",Str1
Str1→A
ClrHome
Disp "Number("+Str1+",?)
Input "",Str2
Str2→B
ClrHome

If A>B
Then
Disp "Faulty Input"
Stop
End

{Rest of code}
Str1/Str2 and A/B are not compatible data types. I don't think your code is valid and I'm surprised you haven't gotten an OS error. You need to use the expr() token.
expr() evaluates a string and returns a value.


Code:
"41"-> Str1
expr(Str1)->A
Disp A
// should render 41


I think the first thing you need is an understanding of variable types and what they do.
The single letters (A-theta) are called real variables. They can store NUMBERS ONLY (in some cases complex numbers).
The strings (Str0-9) are string variables. They can store TEXT ONLY.
TI-Basic lacks the ability to convert between the two implicitly, a function called typecasting in other languages. If you want to store and compare NUMERICAL values, use the REAL numbers. If you want to store and compare STRINGS, use the STRING variables. It will save you trouble.

**Quick side-note: You *can* use the TI token expr() to cast a string to a number. You cannot reverse that without more work.**
ACagliano wrote:
**Quick side-note: You *can* use the TI token expr() to cast a string to a number. You cannot reverse that without more work.**

On the CE, as of os 5.2, the toString() command fills that gap and allows easy conversion from most data types to a string.
Indeed, TI-basic is similar to java when it comes to variables (not loosely typed, strings remain strings, floats remain floats, etc.)
As stated by ACagliano, if you want to use strings as your input data type, you will have to parse them into floats before comparing them.
Similarly to how if you wanted to compare the values in two strings in java, you would have to parse them into a numeric data type first, using something like parseInt() or parseDouble().
Therefore, your code would look like this:

Code:

ClrHome
Disp "Number(?,?)
Input "",Str1
expr(Str1→A
ClrHome
Disp "Number("+Str1+",?)
Input "",Str2
expr(Str2→B
ClrHome

If A>B
Then
Disp "Faulty Input"
Stop
End

{Rest of code}

If you are using the ti-84 plus CE or ti-83 premium CE with a relatively new OS (5.2+), you can take advantage of the toString() command to get your input in a string, but have your input command set a numeric data type like this:

Code:

ClrHome
Input "Number(?,?)",A
ClrHome
Input "Number("+toString(A)+",?)",B
ClrHome

If A>B
Then
Disp "Faulty Input"
Stop
End

{Rest of code}


Notice you can also use the optional 1st argument from the Input command to replace your Disp (which is what it is meant for), the only difference is that you won't get the newline after your prompt line.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement