mardi 29 juin 2021

For loop in TI-Basic won't repeat

I'm trying to make an interactive Pythagorean Theorem calculator which displays

What is displayed

and waits for you to press the keys A, B, or C (41, 42, 43). The following code works fine, it lets me press exactly 2 keys:

ZStandard
84→Xmin
72→Ymax
ZInteger
FnOff 

{0,100,100,0}→L1
{0,60,0,0}→L2
Plot1(xyLine,L1,L2

Text(60,130,"C"
Text(90,250,"A"
Text(148,150,"B"

DispGraph

0→A
0→B
0→C

For(I,1,2
:0→K
:1→L
:While L
::getKey
::If Ans=45:Then
:::0→L
::End
::If Ans=41 or Ans=42 or Ans=43:Then
:::Ans→K
:::0→L
::End
:End

:If K=0:Then
::Stop
:End

:Disp K,I,A,B,C," "
End

But when I add the following if-else-statement

:If K=41:Then
::Input "A=",A
:Else:If K=42:Then
::Input "B=",B
:Else
::Input "C=",C
:End

in the code, like this:

ZStandard
84→Xmin
72→Ymax
ZInteger
FnOff 

{0,100,100,0}→L1
{0,60,0,0}→L2
Plot1(xyLine,L1,L2

Text(60,130,"C"
Text(90,250,"A"
Text(148,150,"B"

DispGraph

0→A
0→B
0→C

For(I,1,2
:0→K
:1→L
:While L
::getKey
::If Ans=45:Then
:::0→L
::End
::If Ans=41 or Ans=42 or Ans=43:Then
:::Ans→K
:::0→L
::End
:End

:If K=0:Then
::Stop
:End

:If K=41:Then
::Input "A=",A
:Else:If K=42:Then
::Input "B=",B
:Else
::Input "C=",C
:End

:Disp K,I,A,B,C," "
End

It only repeats once. Any help would be highly appreciated.

Aucun commentaire:

Enregistrer un commentaire