Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: holmes221b on December 26, 2010, 10:57:29 pm

Title: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on December 26, 2010, 10:57:29 pm
Strings and I have a love-hate affair going on right now, particularly where my program Chemitab 83+ is concerned. I can't get the program to display all 112 elements correctly. It displays Hydrogen fine, though, and at one point today, I got it to display Hydrogen for all 112 elements. The exit option ('0') also works fine too.

Here's a rough concept of what the code looks like (I'd be completely insane to provide the entire code like this, it's almost 1k lines in length):
Code: [Select]
:Lbl A
:Input "NUMBER? ",N
:If N=0:Goto X
:If N=1:Then
:"HYDROGEN"->Str1
:"H"->Str2
:Goto B
:If N=2:Then
:"HELIUM"->Str1
:"HE"->Str2
:GotoB
...
:If N=112:Then
:"COPERNICIUM"->Str1
:"CN"->Str2
:Goto B
:Lbl B
:ClrHome
:Disp Str2
:Disp Str1
:Pause
:Goto A
...
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: nemo on December 26, 2010, 11:01:50 pm
you need End's with those if/then statements.
Code: [Select]
If X=1
Disp "x is 1"
Disp "always displayed"
If X=1:Then
Disp "X=1"
Disp "Displayed when x=1"
End

by the way, 1000 posts
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on December 26, 2010, 11:05:01 pm
So how would I use End in my program?/me is kinda confused.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: Raylin on December 26, 2010, 11:08:35 pm
End ends a Then, Repeat, For or While Loop.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: nemo on December 26, 2010, 11:09:12 pm
So how would I use End in my program?/me is kinda confused.

If (expression):Then
//code executed if expression is true
//more code being executed.
End
//code executed always
If (expression)
//code executed if expression is true
//code executed always

if you don't understand this, you may want to search TI|BD's starter tutorial

press [Prgm][7] to get the End token.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: jnesselr on December 26, 2010, 11:11:31 pm
It essentially defines a block of the if statement. In Basic, you don't need one for If, unless you want multiple lines to run. So:
Code: [Select]
If A=1
line A
line B
line C
if A=1, then Line A would be run. but A and B are run here.
Code: [Select]
if A=1:Then
line A
line B
End
line C
the same thing applies for Repeat and While, except they must be used with an End. (No Then, either. So this is a repeat loop that waits for a keypress)
Code: [Select]
Repeat Getkey
End
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on December 26, 2010, 11:19:53 pm
I probably should clarify that the code in nemo's post confused me...
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: Raylin on December 26, 2010, 11:22:01 pm
If you use an If conditional (no Then), only the following line will be executed if the conditional is true.
If you use an If conditional (with Then), then that entire block of code until the next End with be executed when the conditional is true.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on December 26, 2010, 11:31:51 pm
Ah, okay.
Now it's all clear to me.

Nice avatar, by the way.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: Raylin on December 26, 2010, 11:42:03 pm
:) Thank you, sir.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on December 26, 2010, 11:48:28 pm
Ma'am. This ain't the military.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: Raylin on December 26, 2010, 11:53:39 pm
Ohshi-

You're a legit girl.

Oh shi-

o.o
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on December 26, 2010, 11:54:33 pm
And it's that time of the month for me too--so it's impossible for me to forget that fact for myself.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: Raylin on December 26, 2010, 11:55:33 pm
Uhm.

Well.

You have my sincerest apologies, madame. (Ma'am seems so... informal.)
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: meishe91 on December 27, 2010, 03:27:07 am
Everyone also forgot to mention that you need End at the end of an If/Then/Else statement. If you need anymore help just let us now :)
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on January 07, 2011, 02:49:50 pm
Forgot to mention here that I've gotten it to work.

Everyone also forgot to mention that you need End at the end of an If/Then/Else statement. If you need anymore help just let us now :)
It's alright, though, I already knew about that anyways. And thanks for the offer, but I already knew that everyone here is willing to help me out if I just ask (I speak from experience, in fact).
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: DJ Omnimaga on January 08, 2011, 08:31:13 pm
Cool to hear. ;D

About End statements, in TI-BASIC for the 83+ it's even more confusing because unlike other languages, there's one End instruction for everything, instead of EndWhile, EndIf, Next and EndRepeat, so when you have about 5 nested ifs/for/whiles along with a few scattered ifs in your code, it gets confusing to figure out how many End commands you need at the end.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on January 10, 2011, 12:03:46 pm
/me wasn't able to start a new thread for this (school connection isn't allowing me to start new topics anywhere on Omnimaga)

So today in Precalculus II, we started learning about angles and their measure (that's practically the actual title of the section). During that time, I came up with two different ideas for new programs to code:
-a program to convert radians to degrees, minutes, seconds as well as convert degrees, minutes, seconds to radians
-a program to convert decimals to degrees, minutes, seconds as well as convert degrees, minutes, seconds to decimals.

My question is this: Is it possible to create a program to do the latter? The reason I ask this is because in my textbook it mentions that to convert decimals to degrees, you have to change the calculator's mode to get the correct answer.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: JosJuice on January 10, 2011, 12:52:06 pm
My question is this: Is it possible to create a program to do the latter? The reason I ask this is because in my textbook it mentions that to convert decimals to degrees, you have to change the calculator's mode to get the correct answer.
Very likely. I'm not sure how to do it, though.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: AngelFish on January 10, 2011, 01:28:12 pm
-a program to convert decimals to degrees, minutes, seconds as well as convert degrees, minutes, seconds to decimals.

My question is this: Is it possible to create a program to do the latter? The reason I ask this is because in my textbook it mentions that to convert decimals to degrees, you have to change the calculator's mode to get the correct answer.

It's possible and actually quite easy. I don't have my link cable right now, so here's the code:

Code: [Select]
Menu("","▶DMS",A,"▶Dec,B
Lbl A
Input "Decimal? ",A
ClrHome
60fPart(A→B
60fPart(B→C
Disp int(A),int(B),int(Ans
Pause
Stop
Lbl B
Input "D? ",A
Input "M? ",B
Input "S? ",C
(C/60+B)/60+A
Disp Ans
/me waits for Runer to reduce the code size down to six bytes with his incredible optizimations
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: JosJuice on January 10, 2011, 02:16:53 pm
Instead of
Code: [Select]
Input "D? ",A
Input "M? ",B
Input "S? ",C
, maybe you could use
Code: [Select]
Prompt D,M,S
instead? :P

And maybe change Decimal to DECIMAL.

EDIT: Instead of:
Code: [Select]
Disp int(A),int(B),int(Ans
Pause
do this:
Code: [Select]
Disp int(A),int(B
Pause int(Ans

EDIT2: I think you misspelled the first line. It should be Menu("","▶DMS",A,"▶Dec",B, not Menu("","▶DMS",A,"▶Dec,B
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: SirCmpwn on January 10, 2011, 02:22:33 pm
My question is this: Is it possible to create a program to do the latter? The reason I ask this is because in my textbook it mentions that to convert decimals to degrees, you have to change the calculator's mode to get the correct answer.
Not only is it possible, it's built into TIOS.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on January 10, 2011, 04:36:03 pm
Not only is it possible, it's built into TIOS.
Can you tell I don't have an owner's manual for my calculator? xD
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: SirCmpwn on January 10, 2011, 04:36:27 pm
Can you tell I've read mine cover to cover? XD
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on January 10, 2011, 05:06:13 pm
I think I can make a smaller program than what you've all come up with for me (if you remove the "fluff" I added to make it into a "proper" program)...whether or not it actually works though, I don't know yet, I haven't tried this out on my calc yet. Also, it's set up with the assumption that you have already set your mode to DEGREE.

Code: ("prgmDMS2D") [Select]
:Lbl A
:Input "DMS=1, DEC=2", N
:If N=1:Then
:ClrHome
:Prompt D,M,S
:Disp DºM'S''
:Pause
:Goto B
:End
:If N=2:Then
:ClrHome
:Prompt N
:Disp N▶DMS
:Pause
:Goto B
:End
:If N≠1
:If N≠2
:Then
:ClrHome
:Disp "TRY AGAIN!"
:Pause
:Goto A
:End
:Lbl B
:ClrHome
:Input "PRESS 1 TO REPEAT", X
:If X=1:Then
:Goto A
:End
:If X≠1:Then
:Stop


edit: Okay it doesn't work. Keeps getting ERR:SYNTAX on the DMS to DEC section of the code.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: Raylin on January 10, 2011, 05:33:17 pm
Some of those If's won't work, I don't think...
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on January 10, 2011, 05:35:42 pm
They all should, this code is based off of Chemitab 83+

doesn't mean that they will work, though.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: c.sprinkle on January 10, 2011, 05:40:59 pm
Try this:
Code: ("prgmDMS2D") [Select]
:Lbl A
:Input "DMS=1, DEC=2", N
:ClrHome

:If N=1
:Then
:Prompt D,M,S
:Disp DºM'S''
:Goto B
:End

:If N=2
:Then
:Prompt N
:Disp N▶DMS
:Goto B
:End
:If N≠1 and N≠2
:Then
:ClrHome
:Disp "Try again!"
:Pause
:Goto A
:End

:Lbl B
:Pause
:ClrHome
:Input "PRESS 1 TO REPEAT", X
:If X=1
:Goto A
:If X≠1
:Stop
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: AngelFish on January 10, 2011, 05:42:10 pm
Er, Raylin's right.

When you have more than one line in a conditional, you must always have
Code: [Select]
If <condition>:Then
<Code>
<Code>
End

If you do not have a :Then statement, then the calculator does this instead:
Code: [Select]
If <Condition>
<line of Code to be executed if the condition is true and skipped if false>
<line of code to be executed if the condition is false and skipped if true>
<rest of code>

Any End statements are regarded as not having associated commands and bring up errors. You didn't follow the conditionals correctly, so that's probably at least one problem with your code.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: holmes221b on January 10, 2011, 05:43:27 pm
I can't even get that far in it, because of the ERR:SYNTAX.
It doesn't like the M' part.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: AngelFish on January 10, 2011, 05:50:52 pm
Try Disp D,"º",M," ' "," '' "or Text to display them.
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: DJ Omnimaga on January 11, 2011, 03:23:24 pm
If you do not have a :Then statement, then the calculator does this instead:
Code: [Select]
If <Condition>
<line of Code to be executed if the condition is true and skipped if false>
<line of code to be executed if the condition is false and skipped if true>
<rest of code>
Shouldn't this be:
Code: [Select]
If <Condition>
<line of Code to be executed if the condition is true and skipped if false>
<rest of code>

? ???
Title: Re: Ready to give up on a program (since I can't just pull my hair out)
Post by: AngelFish on January 11, 2011, 03:24:23 pm
Er, yes. Thanks for correcting that.