Author Topic: 83+ to nspire nx rewrite fail  (Read 6289 times)

0 Members and 2 Guests are viewing this topic.

Offline ShortsOnFire79

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
    • Deviantart Gallery
83+ to nspire nx rewrite fail
« on: March 26, 2012, 12:07:44 am »
Hey,

So I'm in the process of rewriting some of my more useful programs from my TI-83 plus onto my TI-nspire cx cas.
I've written myself a program that will ask for 4 variables, and depending on which variable is set as the one to solve for, it will perform a certain equation.  By making my variables equal each other (ex: p=p) then that tells my code to solve for that variable.

Heres the code thats on my 83, it works just fine.
Spoiler For Spoiler:
:Disp "pv=(0.08206)nt"
:Input "enter p:atm=",p
:Input "enter v:l=",v
:Input "enter n=",n
:Input "enter t:k=",t
:If p=p:then
:Disp (0.08206nt)/v
:If v=v:then
:Disp (0.08206nt)/p
:If n=n:then
:Disp (pv)/(0.08206t0
:If t=t:then
:Disp (pv)/(n0.08206)

I'm basically writing the same exact code, except without the 'input' command, since it isn't in the catalog function on the cas, but that is what the 'define' command is for.  Here is the code I have on my cas, it gives me syntax errors when I try to 'check it', and when I run it, it says I have too many arguments.  I also tried writing the code with instead of 'func', using 'prgm', which didn't change anything.  I attempted to have the code recognize the variable '?' which would symbolize which variable to solve for, but it would not recognize it either.
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
func
If p=p, then disp 0.08206nt/v
If v=v, then disp 0.08206nt/p
If n=n, then disp pv/0.08206t
If t=t, then disp pv/0.08206n
endfunc

I know that my knowledge of coding is quite diminutive, which is why I'm here, to learn.  So feel free to poke and make fun of my codes and how sloppy it is and whatnot.  I'm sure there are numerous ways to shorten my code, but I only know the very basics at the moment.  Any bits of knowledge you could offer me would be greatly received, I am here to learn!

Thank you for your time. :)

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: 83+ to nspire nx rewrite fail
« Reply #1 on: March 26, 2012, 05:14:46 am »
First of all, input can be gained from the Request (for numerical values) and RequestStr (for strings).
The major problem that's causing all the trouble is that you don't close the if statements.
On the TI-Nspire you have to do this:
Spoiler For Spoiler:
If <condition> then
<actions to perform>
EndIf

Also, all the variables are ALWAYS equal to themselves. So v=v no matter what. So you will always get four results.
Here's how I would've done it:
Spoiler For Spoiler:
Your code, but with closed if statments. Will always return four answers
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p=p Then
 Disp ((0.08206*n*t)/(v))
EndIf
If v=v Then
 Disp ((0.08206*n*t)/(p))
EndIf
If n=n Then
 Disp ((p*v)/(0.08206))*t
EndIf
If t=t Then
 Disp ((p*v)/(0.08206))*n
EndIf
EndPrgm

Another option: make the variable to solve different from the others. The gaslaw for example would never have negative numbers or zero, so consider this (Stop terminates the program):
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p<0 Then
 Disp ((0.08206*n*t)/(v))
 Stop
EndIf
If v<0 Then
 Disp ((0.08206*n*t)/(p))
 Stop
EndIf
If n<0 Then
 Disp ((p*v)/(0.08206))*t
 Stop
EndIf
If t<0 Then
 Disp ((p*v)/(0.08206))*n
 Stop
EndIf
EndPrgm

Personally, I would do this:
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p=0 Then
 Disp "p=",((0.08206*n*t)/(v))
ElseIf v=0 Then
 Disp "v=",((0.08206*n*t)/(p))
ElseIf n=0 Then
 Disp "n=",((p*v)/(0.08206))*t
ElseIf t=0 Then
 Disp "t=",((p*v)/(0.08206))*n
Else
 Disp "Error: nothing to solve, check syntax."
EndIf
EndPrgm

Finally, not really needed, if you want nice input:
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
Request "Enter p:atm=",p
Request "Enter v:l=:",p
Request "Enter n=",n
Request "Enter t:k=:

If p=0 Then
 Disp "p=",((0.08206*n*t)/(v))
ElseIf v=0 Then
 Disp "v=",((0.08206*n*t)/(p))
ElseIf n=0 Then
 Disp "n=",((p*v)/(0.08206))*t
ElseIf t=0 Then
 Disp "t=",((p*v)/(0.08206))*n
Else
 Disp "Error: nothing to solve, check syntax."
EndIf
EndPrgm

I hope this was helpful. And if you want to learn, check my tutorial (link coming soon in my sig)
« Last Edit: March 26, 2012, 05:28:25 am by ElementCoder »

Some people need a high five in the face... with a chair.
~EC

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: 83+ to nspire nx rewrite fail
« Reply #2 on: March 26, 2012, 06:00:17 am »
Yeah TI-nspire Basic Code is different and cannot be written as concisely as Code on the TI-83+.
I'm actually surprised that the TI-83+ Code actually works. I didn't know that EndIfs were not needed.

And Hi ElementCoder! I'm Jonius7, also known as jhgenius01 (you would have visited my website at jhgenius01.webs.com)
Haven't really seen you around that much, but good to see you!
Wonder if superbany has an account here.
« Last Edit: March 26, 2012, 06:01:22 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline ShortsOnFire79

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
    • Deviantart Gallery
Re: 83+ to nspire nx rewrite fail
« Reply #3 on: March 26, 2012, 08:00:22 pm »
First of all, input can be gained from the Request (for numerical values) and RequestStr (for strings).
The major problem that's causing all the trouble is that you don't close the if statements.
On the TI-Nspire you have to do this:
Spoiler For Spoiler:
If <condition> then
<actions to perform>
EndIf

Personally, I would do this:
Spoiler For Spoiler:
Define gaslaw(p,v,n,t)=
Prgm
If p=0 Then
 Disp "p=",((0.08206*n*t)/(v))
ElseIf v=0 Then
 Disp "v=",((0.08206*n*t)/(p))
ElseIf n=0 Then
 Disp "n=",((p*v)/(0.08206))*t
ElseIf t=0 Then
 Disp "t=",((p*v)/(0.08206))*n
Else
 Disp "Error: nothing to solve, check syntax."
EndIf
EndPrgm
I hope this was helpful. And if you want to learn, check my tutorial (link coming soon in my sig)

Thanks for walking me through the if-thens, that'll be really helpful on my next project.

I ended up using your code that you personally would use.  Works great!  One thing I don't understand though, is why at the second to last line, you have an EndIf?  Is that to tell the code to end, if the previous error was witnessed?

Also, what will your tutorials be covering?  If they're as descriptive as the post you left me, I will surely check them out! Thank you!

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: 83+ to nspire nx rewrite fail
« Reply #4 on: March 26, 2012, 08:12:36 pm »
If <condition> then
<actions to perform>
EndIf

From this code example, the EndIf is a command that Ends the If statement

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: 83+ to nspire nx rewrite fail
« Reply #5 on: March 27, 2012, 07:53:05 am »
Is EndIf or End not required in TI-BASIC (83/84)?
I know that End is required in Casio Basic and EndIf in TI-nspire Basic
End (for function in Lua) too.
« Last Edit: March 27, 2012, 07:53:24 am by Jonius7 »
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: 83+ to nspire nx rewrite fail
« Reply #6 on: March 27, 2012, 10:15:01 am »
Also, what will your tutorials be covering?  If they're as descriptive as the post you left me, I will surely check them out! Thank you!

I plan to make them as descriptive as my post, with useful examples and quizes to test knowledge :P

@Jonius7: yeah, lets say I took a forced break. School and such, and with exams upcoming I don't know how much time I can spend around here and coding stuff. I'm doing a little too much atm so I'm a bit *.* (learning java, learning lua (does anyone know a good tutorial?), playing a lot of guitar :P)

Some people need a high five in the face... with a chair.
~EC

Offline Jonius7

  • python! Lua!
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1918
  • Rating: +82/-18
  • Still bringing new dimensions to the TI-nspire...
    • View Profile
    • TI Stadium
Re: 83+ to nspire nx rewrite fail
« Reply #7 on: March 27, 2012, 08:11:25 pm »
Yeah, true, posting posts and stuff is definitely time consuming. But I've been here a while, so I guess it's not too bad. Just that I need some good projects!
Programmed some CASIO Basic in the past
DJ Omnimaga Music Discographist ;)
DJ Omnimaga Discography
My Own Music!
My Released Projects (Updated 2015/05/08)
TI-nspire BASIC
TI-nspire Hold 'em
Health Bar
Scissors Paper Rock
TI-nspire Lua
Numstrat
TI-nspire Hold 'em Lua
Transport Chooser
Secret Project (at v0.08.2 - 2015/05/08)
Spoiler For Extra To-Be-Sorted Clutter:

Spoiler For Relegated Projects:
TI-nspire BASIC
Battle of 16s (stalled) | sTIck RPG (stalled) | Monopoly (stalled) | Cosmic Legions (stalled)
Axe Parser
Doodle God (stalled while I go and learn some Axe)

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: 83+ to nspire nx rewrite fail
« Reply #8 on: March 27, 2012, 09:24:06 pm »
Is EndIf or End not required in TI-BASIC (83/84)?
I know that End is required in Casio Basic and EndIf in TI-nspire Basic
End (for function in Lua) too.


84+ only uses End, there is no such thing as EndIf (unless you use Axe :P )

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: 83+ to nspire nx rewrite fail
« Reply #9 on: March 27, 2012, 10:27:59 pm »
learning lua (does anyone know a good tutorial?)

For Lua, first learn Lua itself, http://www.lua.org/pil/
Then, head to Inspired Lua for Nspire API, www.inspired-lua.org

Good luck!