I have a program that I am making where the goal is to get to the highest value using only expressions and four 4's. Is there any way that I could restrict the user so they can't press the 1-3 and 5-0 buttons?
I'm assuming this is on the TI-84 family of calculators? You just check for the key value associated with 4 and ignore everything else.


Code:
While K≠91
getKey->K
If K=82
Then
*code*
End
End


91 is Sto->, basically it's used as a quit key. You can use any other value/key though.
No, I am building it for the TI-83, as that is what I have. What do you think of this? I have a program that can tell you what the getKey value is of any button when you run the program and hit a button. I made it so that whenever the enter key is hit, it starts over. Here is the code:

Code:
ClrHome
Lbl A
Repeat A!=0
getKey->A
End
If A=105
Goto A
ClrHome
Output(1,1,A)
Pause
DelVar A
ClrHome
Output(1,1,"")


P.S. getKey value 105 is the enter key.

Edit: I see where you are coming from, but the button for the number 4 is not the only button that can be used, it is just the buttons for the numbers 1-3 and 5-9 that can't be used.

Edit 2: Would this code work:

Code:
ClrHome
Lbl A
Repeat A!=0
getKey->A
End
If A=102 or A=92 or A=93 or A=94 or A=83 or A=84 or A=72 or A=73 or A=74
Goto A
ClrHome
Output(1,1,"This is either a four or a different expression."
Pause
DelVar A
ClrHome
Output(1,1,"")
MrDew25 wrote:
No, I am building it for the TI-83, as that is what I have.


Close enough, same getKey values. In fact the image I posted says it's for the TI-83 Smile

Simple then:

Code:
While K≠91
 getKey->K
 If K≠92 or K≠92 or K≠93 or K≠94 or K≠83 or K≠84 or K≠72 or K≠93 or K≠94
 Then
  If K=82
  Then
   *code*
  End
 End
End
Kerm, I have a question for you.

I don't want people to press the buttons 1, 2, 3, 5, 6, 7, 8, 9 and 0. I want it so that this rule applies, but they type in their answer thanks to an Input command. Is this possible?

Again, I want them to input their answer, say 4-4+4-4, but I don't want them to type in any number besides 4.

Edit: How does this look?

Code:
ClrHome
Input "",Str1
inString("123567890",Str1)->B
If B!=0
Disp "Wrong Button!"
Try this:

Code:

While 1
ClrHome
Input "",Str1
If inString(Str1,"1")+inString(Str1,"2")+inString(Str1,"3")+inString(Str1,"5")+inString(Str1,"6")+inString(Str1,"7")+inString(Str1,"8")+inString(Str1,"9")+inString(Str1,"0")
Then
Disp "Only can contain number 4"
Else
Disp expr(Str1)
End

(The inString( is on the same line as the If command)

This will check that your code does not have any numbers, but any letters will throw out an error in the code.
For how inString works, check out http://tibasicdev.wikidot.com/instring
That is what I needed. Thanks dude!
More cleaner, as Hooloovoo suggested and fixed a whole lot of things:

Code:
"012356789"->Str2
While 1
 Input "",Str1
 0->B
 For(A,1,9)
  B+inString(Str1,sub(Str2,A,1))->B
 End
 If B
 Then
  Disp "Only can contain number 4"
 Else
  Disp expr(Str1)
 End
 Repeat getKey
 End
End

Mostly helped me get back in practice coding basic Razz
Thanks for all of the help. I have added you in as a special thanks for helping me make this code.
A little late, but a little bit optimized... Razz

This:

Code:
"012356789"->Str2
0->B
For(A,1,9)
B+inString(Str1,sub(Str2,A,1))->B
End
If B

Can be:

Code:
If sum(seq(inString(Str1,sub("012356789",A,1)),A,1,9


Not to point out a program or anything, but that 21 Game in the archives has some useful things in it... Razz
Thank you for beating me to posting that optimization, Mateo. Smile You seem to have taken over the "effective use of seq()" mantle from Weregoose, for which I salute you. Let me suggest one fix that will make this work in more circumstances:
Code:
If not(prod(seq(inString(Str1,sub("012356789",A,1)),A,1,9

With prod(, a single 0 (character is not a number) will make the entire product zero, and trigger the error message. With sum(, every character would have to be a non-number to trigger the message. Smile

This seems like a prime candidate for the Useful TI-BASIC Routines and Code Fragments thread. Smile
  
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