Hi all,

I am trying to make a simple reverse polish notation calculator and I am having a problem with my stack going out of the array dimensions. I have tried many different attempts and tricks for it to work, but no luck yet. I read on the TI-Basic Developer wiki site that the return command could be used to break out of a loop, just as the break statement in C++ does, but the only thing it does is as expected, end the program. The error occurs when S is decremented and the program checks for an element that is out of range. Any ideas how I can rearrange my loop or break out of it to prevent the program from checking for list element 0?

Code:
``` :Clrhome :SetUpEditor ʟSTACK :1→S :"?→Str2 :Input "STR1: ",Str1 :Str1+"?→Str1 :For(θ,1,length(Str1 :If instring("-.0123456789",sub(Str1,θ,1 :Then :While instring("-.0123456789",sub(Str1,θ,1 :Str2+sub(Str1,θ,1→Str2 :θ+1→θ :End :Str2+" "→Str2 :End :If sub(Str1,θ,1)="^" :Then :1→ʟSTACK(S :S+1→S :End :If sub(Str1,θ,1)="*" :Then :If dim(ʟSTACK)=0 :Then :2→ʟSTACK(S :S+1→S :Else :S-1→S :While S>0 and ʟSTACK(S)≤2 :Str2+sub("^*",ʟSTACK(S),1→Str2 :Str2+" "→Str2 :S-1→S :End :S→dim(ʟSTACK :S+1→S :End :End :End ```
[/code]

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.

»
» 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