i dont know what is wrong i keep getting a syntax error that takes me to to after the "Then"


Code:
:Prompt I,X,A
:If A=0
:Then
:I->F
:X/I->T
:Goto X
:Else
You need to end If statement blocks with an :End command, else the interpreter doesn't see a complete If block.

Code:
:Prompt I,X,A
:If A=0
:Then 
:I->F 
:X/I->T
:Goto X
:Else
(have some code here maybe?, or remove the :Else)
:End
OHHHH...
I didnt know i needed tod do that. Thanks for the help!
Your first error is that you have an Else without a set of statements and an End. If you want to do one thing if the condition is true (ie, A=0), and another thing if the condition is false (ie, A is not equal to 0), then you use If/Then/.../Else/.../End. If you just want to do things when the condition is true (A=0), then you use If A=0/Then/.../End. However, you're setting yourself up for what is called a memory leak by putting a Goto in an If/Then/Else/End or If/Then/End construct: your program will slow down, and eventually stop with ERR:MEMORY. To solve this, you could try the following code:
Code:
:Prompt I,X,A
:If A=0
:Then 
:I->F 
:X/I->T
:End
:If A=0
Goto X
Finally, may I very self-promotingly recommend taking a look at some of the content in Programming the TI-83 Plus/TI-84 Plus to learn more about good TI-BASIC programming practices?
There's more code after the else, but I didn't have an End to it. Thanks.
Plus, as an optimization, instead of doing:

Code:
A=0

You can do:

Code:
not(A


Which is one byte less. Good luck on your project! Very Happy Any ideas on what it is? Smile
Ahhh, that'll do it! Please feel free to continue to use this topic for more TI-BASIC questions that come up as you work on your program, and if this is a project you think other people might find cool, consider starting a Your Projects topic for it.
Alright its still not working, same error. same place. I'm new to this, so please try and keep it simple for me.



Code:
Prompt I,X,A
If A=0
Then
I->F
X/I->T
Goto X
Else
sqrt(I^^2+2AX)->F
sqrt((2X)/A)->T
End
Lbl X
regand: Did you type the word "Then" out letter-by-letter, or did you get it from [PRGM][2]?

Edit: Also, because of the way If/Then/Else/End skips from the Else to the End, the Goto and Lbl are unnecessary there.
I typed it in using source coder, It turned blue so I though it was good. good to know about the Lbl.
regand1 wrote:
I typed it in using source coder, It turned blue so I though it was good. good to know about the Lbl.
Ah, I see. Yes, but then it looks like you have spaces after the Then, which is probably the problem. Make sure that you don't have trailing spaces after commands.
I fixed it and seems to be working now. Also since you seem to be helpful.. when I run the code i get a nonreal ans. Can nonreal answers not be assigned to a variable? in this case it should have been asigned to variable T
regand1 wrote:
I fixed it and seems to be working now. Also since you seem to be helpful.. when I run the code i get a nonreal ans. Can nonreal answers not be assigned to a variable? in this case it should have been asigned to variable T
Nonreal answers are not allowed when you're in real mode. If you want your program to work with complex numbers, you'll need to use the a+bi (rectangular) or polar complex number modes. In SourceCoder, simply put "a+bi" on a line by itself to set the rectangular complex mode.
I just changed the mode of the emulator. Mine is usually in a+bi anyways.
Thanks for the help.
  
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