Post Reply 
New guy and programming problem
08-28-2017, 02:20 PM
Post: #22
RE: New guy and programming problem
So for completeness' sake, I'll add the response I left to you when you asked this question on my 42s programming video.

Sure, so what's happening is that if you enter a new value for R1 or R2 the stack is lifting and the old value is now in the Y portion of the stack, so ultimately your program is calculating the old R2 + 1/(new R2) and then 1/x.

A couple of solutions: the most straightforward is probably to store the intermediate value, so after the first 1/X, STO 00 and then after the second 1/X, RCL 00.

Or, perhaps a better practice is to create the variables first, then perform the operations:
Code:
LABEL "PAR2"
INPUT R1
INPUT R2
1/X
RCL R1
1/X
+
1/X
END

Lastly, if you wanted to be really streamlined, you could do away with INPUT altogether and just enter your values into the stack before executing the program
Code:
LABEL "PAR2"
1/X
X <> Y
1/X
+
1/X
END
(Run by entering R1 ENTER R2 XEQ PAR2)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: New guy and programming problem - Logan - 08-28-2017 02:20 PM
RE: New guy and programming problem - sasa - 09-01-2018, 03:18 PM
RE: New guy and programming problem - sasa - 09-01-2018, 05:33 PM



User(s) browsing this thread: 1 Guest(s)