So, basically I am working on a game (multiplayer mode from 2 to 10 players) where you are given a random integer from 50 to 1000, and each player has to give his guess to what the square root of this number is. This guess is then stored into a variable, and later in a list.

I found a way to prevent direct cheating : trying to input a number with more than 6 decimals (= trying to input sqrt(number ) will result in a cheating message.

But, by using round( you can easily bypass this. I was wondering if anyone could help me on that, since the calculator can't check while you input (with a getKey loop for example), nor when your value gets stored into the variable.

Instead of inputting a number, you could have users input a string and then use the expr( command:

Input Str1

expr(Str1

In between, you can put some validation code to check if the user used a common command like √(). For this, you can use the inString( command, though I would actually check if all characters in the string are numbers and/or a period, not whether they used the √() command or not. That way, you eliminate the chance of any operator being used, since ^(1/2) will also square root a number, among other things.

Timothy Foster - @tfAuroratide

Auroratide.com - Go here if you're nerdy like me

Either you do it by archiving and unarchiving the integer variable or you encrypt the number.

We have a complete page to encryption in here

For example, when you have this, you have combined archiving and encryption. This is a variant for endless players on one calc:

```
:randInt(50,1000→A
:randInt(2,500→B. //encryption
:A*B→A
:Archive B //Archiving
:Lbl 1
:Input “Guess: “, C
:C→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:Unarchive B
:√(A/B→A
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Pause A
```

Edit: Ok, didnt seeTimothy Fosters post. His idea is better

Wake me, when you need me.

Ok, i put Timothys Idea together with mine:

```
:randInt(50,1000→A
:randInt(2,500→B. //encryption
:A*B→A
:Archive B //Archiving
:Lbl 1
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If inString(“1234567890“,sub(Str1,I,1))=0 //if any char isnt a number
:Then
:Pause “Invalid input
:Goto 1
:End
:End
:expr(Str1→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:Unarchive B
:√(A/B→A
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Pause A
```

I have to admit, the goto in the for Loop is not good due to upcoming memory leaks, but fixing this would destroy the codes readability and would make understanding the code harder.

Then I also have a own question:

`:If inString(“1234567890“,sub(Str1,I,1))=0`

Is this the same as:

`:If not(inString(“1234567890“,sub(Str1,I,1))`

??

Wake me, when you need me.

Thanks a lot for the answers guys, helped me a lot !

By the way, there are 2 reasons why the max number of players is 10 (I could easily increase it of course) :

- It's not often we are more than 10 to play this game x)

- It is easier to see each player's answer, plus the correct answer in the end when there are 10 or less players.

I am actually considering to upload the code so it can be improved, and shared because that's a game I find quite funny (especially during math lessons :p)… So is this the right section to post it ?

It is your own created thread, and if you want to post your code here, you can post it. Feel free to post nearly anything you want, as long as you dont break any rules

that's a game I find quite funny (especially during math lessons :

Due to you being able to program even on a calculator, you should find math interesting xD

Wake me, when you need me.

I actually play this during math because the class and the teacher are too slow for me, I learnt and understood everything so I program on my calculator x)

Haha, you remember me of myself one year ago :D

Though now I have to pay at least half attention.

Wake me, when you need me.

Actually, THIS was the reason I started programming!

One day our teacher showed us some basic commands for the TI-84 + but I didn't understood anything and didn't care about it. But as soon as I was really bored in math, I just tried it out again and that's how I started programming :D

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8

I learned Basic completely by myself (and this site) because of boreness in school xD

But I think, Basic is by far the easiest programming language. I dont know any other language, where you for example can combine Boolean values with floats

Wake me, when you need me.

Well, I just realized that one safety process is enough. In my post I made 3 safety processes, even encryption, but I think Timothys idea is enough to prevent cheating, so here is a good and easy understandable code:

```
:√(randInt(50,1000→A
:Lbl 1
:ClrHome
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If not(inString(“1234567890“,sub(Str1,I,1 //if any char isnt a number
:Then
:Pause “Invalid input
:Goto 1
:End
:End
:expr(Str1→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Pause A
```

Due to looking whether any letter is not a number, you are only able to give integers as an input, or an invalid input message will appear.

Wake me, when you need me.

Yeah, that's what I ended up copying in my program :)

(modified it a bit though, you've got a Goto going out of a loop)

Fixing the goto within the loop is very easy, I just didnt do it cause of readability. Fixing it, you have:

```
:√(randInt(50,1000→A
:Lbl 1
:DelVar D
:ClrHome
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If not(inString(“1234567890“,sub(Str1,I,1 //if any char isnt a number
:1→D
:End
:If D
:Then
:Pause “Invalid Input
:Goto 1
:End
:expr(Str1→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Pause A
```

How did you fix it?

Just because of interest

Wake me, when you need me.

hmmm… To be honest I like to make fun of my friends trying to break the program while I add more and more features to detect cheating, so it just sets their answer to 0 and the calculator later tells them they cheated and they have to do the walk of shame x)

But If I had to do it I would have done something like what you did, adding an extra variable. (would add the column though because the game is often about a precision of 10^-3 or even 10^-4) (oh and I think I didn't mention clearly that the calculator does give you the variable A, and then you have to find its square root).

Ok, then we have the following code.

I also added the feature to guess a not integer: a float. But you still cant cheat, I think

```
:randInt(50,1000→A
:Lbl 1
:DelVar D
:ClrHome
:Disp “The number is
:Disp A
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
:1→D
:End
:If D
:Then
:Pause “Invalid Input
:Goto 1
:End
:expr(Str1→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:√(A→A
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Disp A
:Disp “which is the
:Disp “square root of
:A^2→A
:Pause A
```

And the code with the walk of shame is (if I understood right):

```
:randInt(50,1000→A
:Lbl 1
:DelVar D
:ClrHome
:Disp “The number is
:Disp A
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
:1→D
:End
:If D
:Then
:“0→Str1
:Pause “Due to cheating your guess was set to 0. Dont worry you still have chances to win
:End
:expr(Str1→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:√(A→A
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Disp A
:Disp “which is the
:Disp “square root of
:A^2→A
:Pause A
```

Wake me, when you need me.

This game is really simple yet funny! I will play with my mates as school as soon as vacation is over.

I think it would be even more shameful for the player if at the end the calculator shows the list with the numbers of every player and if a player cheated then the calc stores -1 as value and by this the calc can detect it later and show "cheated" when the game is over.

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8

Where do you live that you still have vacations. I am at school again for a few weeks.

With adding the list at the End you would have this code:

```
:randInt(50,1000→A
:Lbl 1
:DelVar D
:ClrHome
:Disp “The number is
:Disp A
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
:1→D
:End
:If D
:Then
:“0→Str1
:Pause “Due to cheating your guess was set to 0. Dont worry you still have chances to win
:End
:expr(Str1→L1(1+dim(L1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:√(A→A
:min(abs(A-L1→F
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Disp A
:Disp “which is the
:Disp “square root of
:A^2→A
:Pause A
:For(I,1,dim(L1
:ClrHome
:Disp “The
:Disp I
:Disp “User
:If not(L1(I
:Then
:Disp “tried cheating
:Else
:Disp “guessed
:Disp L1(I
:End
:Pause
:End
```

Wake me, when you need me.

Le profile:

From: Hanover, Germany

We're having autumn vacations for two weeks right now, one week is already over.

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8

Cool, I am also from Germany, but from Nordrhein-Westfalen, however, I dont know how it is called in English. We dont have autumn vacations yet.

Wake me, when you need me.

Btw dont forget to

`DelVar L1`

or

`ClrList L1`

But then you also have to write 0→dim(L1 at the beginning of the program

Wake me, when you need me.

I tested this program on my calculator yet, and I just saw that you cant just say

:min(abs(A-L1→F

Sry. But I will correct this directly. It is a bit more complicated than that, I just realized

Edit: I got it. You have to replace this single line :min(abs(A-L1→F by

:5000+max(L1→F

:For(I,1,dim(L1

:If abs(A-L1(I))<abs(A-F

:L1(I→F

:End

Wake me, when you need me.

So here is the final code. I also testet if it works and it does

```
:0→dim(L1
:randInt(50,1000→A
:Lbl 1
:DelVar D
:ClrHome
:Disp “The number is
:Disp A
:Input “Guess: “, Str1
:For(I,1,length(Str1
:If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
:1→D
:End
:If D
:Then
:Pause “Invalid Input
:Goto 1
:End
:expr(Str1→L1(1+dim(L1
:If dim(L1<2
:Goto 1
:Menu(“Another input?“,“Yes“,1,“No“,2
:Lbl 2
:√(A→A
:5000+max(L1→F
:For(I,1,dim(L1
:If abs(A-L1(I))<abs(A-F
:L1(I→F
:End
:ClrHome
:Disp “The one who said
:Disp F
:Disp “was closest to
:Disp A
:Disp “which is the
:Disp “square root of
:A^2→A
:Pause A
```

Wake me, when you need me.

why not shortening

```
For(I,1,length(Str1
If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
1→D
End
If D
Then
Pause “Invalid Input
Goto 1
End
```

to

```
For(I,1,length(Str1
If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
Then
Pause “Invalid Input
Goto 1
End
End
```

?

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8

As you may have seen I also had this block above but I changed it due to memory leaks.

In case of interest, read this page: http://tibasicdev.wikidot.com/memory-leaks

Wake me, when you need me.

There is a memory leak anyway, it doesn't matter if you jump out of a loop or a if-then-statement. My "optimization" just offers 2 memory leaks at once. However, I rarely use Gotos (only if there is one action happening really rarely and I'm not motivated to create one more loop) so here is what I would do:

```
0→dim(L1
randInt(50,1E3→A //not the normal E, the exponent E
Lbl 1
Repeat D
DelVar D
ClrHome
Disp “The number is
Disp A
Input “Guess: “, Str1
For(I,1,length(Str1
If not(inString(“1234567890.“,sub(Str1,I,1 //if any char isnt a number or a dot
1→D
End
If D
Pause “Invalid Input
End
expr(Str1→L1(1+dim(L1
If dim(L1<2
Goto 1
Menu(“Another input?“,“Yes“,1,“No“,2
Lbl 2
√(A→A
5000+max(L1→F
For(I,1,dim(L1
If abs(A-L1(I))<abs(A-F
L1(I→F
End
ClrHome
Disp “The one who said
Disp F
Disp “was closest to
Disp A
Disp “which is the
Disp “square root of
A^2→A
Pause A
```

Get futuristicOS 8 for your TI-84+

Learn more about futuristicOS 8