vass123
vass123

Reputation: 11

Factoring program (TI-84 plus)

My Program, just learning how to code calculators today, is not giving me any response but "DONE"

    PROGRAM:FACTORS
    :ClrHome
    :Input "A=", A
    :Input "B=", B
    :Input "C=", C
    :For(D,1,100,1)
    :For(E,1,100,1)
    :If (D*E)=C and (D+E)=B
    :Stop
    :End:End:End
    :Disp D
    :Disp E

Upvotes: 1

Views: 2747

Answers (2)

Vaelus
Vaelus

Reputation: 1065

The problem you have is that stop ends the program entirely instead of just breaking the loops. To fix this, instead or using For loops, you could use Repeat loops:

:1→D
:Repeat (D*E=C and D+E=B) or D=100
::1→E
::Repeat (D*E=C and D+E=B) or E=100
:::E+1→E
::End
::1+D→D
:End

You can ignore the extra colons, they are just there for clarity, but if you leave them the code will still work because they function identically to newlines.

The Repeat loops will break by themselves when the condition D*E=C and D+E=B is met, but you have to handle the initialization and incrementing of the variables E and D yourself.

Also note that your factoring algorithm can fail if A does not equal one. Consider dividing both B and C by A, and then outputting A as a constant factor.

Another error with your code is that you have too many End statements, but fixing this would not fix the program, and it would still exit at the Stop. An If without a Then does not need an End, but only one line will be run if the condition is true. For example:

:If <condition>
:<one statement>

or

:If <condition>
:Then
:<statement 1>
:<statement 2>
:<statement ...>
:<statement n>
:End

Upvotes: 0

Boone
Boone

Reputation: 167

Two problems:

1: All of the ":end"s are on the same line. Do a different one for each

2: This is probably the biggest problem: The "stop" command. "Stop" is used to end the program altogether, and go back to regular function. I'm assuming what you want to do is make it stop looping once D*E=C and once D+E=B. In that case, you can do one of two things: write the breakout code into a repeat loop; for instance

:ClrHome
:Input "A=", A
:Input "B=", B
:Input "C=", C
:For(D,1,100,1)
:For(E,1,100,1)
:Repeat (D*E)=C and (D+E)=B
:End
:End
:End
:Disp D
:Disp E

Or, you can use a Goto command

:If (D*E)=C and (D+E)=B
:Goto Lbl A

And further down in your code, you would put the "Lbl A" above where you wanted it to display your variables

Upvotes: 1

Related Questions