Hi I need help with my code basically I want it to end the program and clrhome when I press clear but it isn't working please help this a test program I am a beginner and here is the script Smile

Repeat K=45
getKey→K
Disp "A >/< B?"
Prompt A,B
If A>B
Disp "A is greater then B"
If A<B
Disp "B is greater then A"
Disp "=========================="
End
ClrHome
Return
So I can get it to loop once but after it tells me which variable is greater I get an error on the 2nd line. So, I moved the getKey command to the bottom, just before the End statement and ran it again. Got the error again but this time it took me to the Repeat K=45. I added DelVar to the top of the program just in case K already equals 45 prior to entering the program.

Sounds like there's some other people working on this so a real answer shouldn't be too far off. Sorry I couldn't be too much help right now.

SourceCoder 3 (GREATER) wrote:
:DelVar K
:Repeat K=45
: Disp "A>/<B?"
: Prompt A,B
: If A>B
: Disp "A is greater then B"
: If A<B
: Disp "B is greater then A"
: Disp "=========================="
: getKey->K
:End
:ClrHome
:Return
Pressing Clear during the prompt will not register, as getKey is used before the Prompt.
The easiest way to add an option to quit would be to wait for a keypress before repeating, and if it is clear, then quit, otherwise, proceed.

Code:
0
While Ans≠45
Disp "A >/< B?"
Prompt A,B
If A>B
Disp "A is greater then B"
If A<B
Disp "B is greater then A"
Disp "=========================="
0
While not(Ans
getKey
End
End
ClrHome

Better code:

Code:
Repeat Ans=45
Disp "A >/< B?"
Prompt A,B
If A>B
Disp "A is greater then B"
If A<B
Disp "B is greater then A"
Disp "=========================="
Repeat Ans
getKey
End
End
ClrHome

You can press enter to continue or clear to exit after everything has been displayed.
Ans holds the result from the last line.
The repeat loop near the bottom waits until a key is pressed, then stores that key in Ans.

Edit:
Not sure why I thought repeat worked that way. I haven't used it in a long time.
Hey, that works! The 0's are there because the calculator will store that value in the variable Ans automatically. You can use that trick to do some math and just "math_equation:Disp Ans" instead of "math_equation->F:Disp F."
EDIT: Thanks for fixing your post commandblockguy! That looks more correct. Very Happy

commandblockguy wrote:
Repeat repeats for a certain number of times.
While repeats as long as an expression is true.

Although yes your way will work. Repeat does not repeat for a certain number of times, that is what a For( loop is for. Wink

TI-Basic Developer wrote:
The code inside a While loop will keep repeating as long as the condition is true ("do this while the condition is true"), and exit as soon as the condition is false.

The code inside a Repeat loop will keep repeating until the condition becomes true ("Repeat this until the condition is true"). So a loop with While will have the opposite condition of the same loop with Repeat.

I believe the reason you had trouble with using the Repeat loop is because:
TI-Basic Developer wrote:
There is another subtle difference. The While loop is a pre-test loop, which means the condition is checked before you enter the loop. If the condition is false, the loop is skipped entirely.
However, the Repeat loop is a post-test loop as the loop is done at least once no matter what. The condition is only checked after a cycle is completed.


If you need any more help with loops, Here is where I got my quotes. Also, the TI Basic Starter Kit is a great place to start learning Basic. If you need any help with the syntax of a command, the Command Index is a great place to find answers.

I hope this helped and Welcome to Cemetech!
Repeat is a do-while loop. You don't need to clear the getkey variable prior to the loop, because Repeat will run once without regard to the condition, at which point getkey will store 0 in the variable if no key is pressed.
Although on the calc, Repeat works as a do-until.

This loop will exit when you hit clear:

Repeat K=45
getKey→K
End
Quote:
If A>B
Disp "A is greater than B"
If A<B
Disp "B is greater than A"



K thanks.
dankcalculatorbro wrote:
Repeat is a do-while loop. You don't need to clear the getkey variable prior to the loop, because Repeat will run once without regard to the condition, at which point getkey will store 0 in the variable if no key is pressed.
Although on the calc, Repeat works as a do-until.

This loop will exit when you hit clear:

Repeat K=45
getKey→K
End


Code:

Repeat getKey=45
End

Wink

Code:
1+(A<B
Disp sub("AB",Ans,1)+" is greater than "+sub("BA",Ans,1

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