x=4? Function « Next Oldest | Next Newest »

 ▼ Shawn Junior Member Posts: 6 Threads: 3 Joined: Jan 1970 09-30-2002, 08:04 PM Hi, I have a HP 42s. I'd like to write my own function or have the calculator evaluate whether x=1? x=2? x=3? x=4?, but the only function that it offers is the relationship to 0. Once the prog. prompts the user to enter 1,2,3 or 4 then it will goto a sub-routine based on the # entered labled w/ corresponding value. Thnx for any help, Shawn ▼ Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 10-01-2002, 06:38 AM Hi; I posted a solution before (30 Sept 2002, 9:24 p.m.) with mistyped values; this is correct. There is an X=Y? function that will do what you want. Look at the samples bellow: (consider FIX 04 as default) - you already have a number in the X-register; the display looks: ``` Y: (anything) X: (your #)``` - you place the number you want to compare: (eg: 4) the display looks: ``` Y: (your #) X: 4.0000 ``` - now you use the function X=Y?; if your number is 4.0000, the display looks: ``` Yes X: 4.0000 ``` - if your number is not 4.0000, the display looks: ``` No X: 4.0000 ``` If you are entering a program, you can choose from both: 1) use specific LBL functions (LBL 01, LBL 02, etc.) If you get in a point where the integer part of the number in the X-register is 1, 2, 3 or 4, you do not need to use X=Y? function; instead, GTO IND ST X will work better. Your program would look like this: (consider step # 20 as a personal choice) ``` (first program steps) . 19 PROMPT (you will input your control # here: 1, 2, 3 or 4) 20 GTO IND ST X 21 LBL 01 (steps when X=1) . 29 RTN 30 LBL 02 (steps when X=2) . 39 RTN 40 LBL 03 (steps when X=3) . . 49 RTN 50 LBL 04 (steps when X=4) . . 59 RTN 60 (rest of the program)``` 2) If your labels have different numbers, your program can be like this: ``` (first program steps) . 19 PROMPT (you input your control # here) 20 1 21 X=Y? 22 GTO xx (label with steps when X=1) 23 CLX 24 2 25 X=Y? 26 GTO yy (label with steps when X=2) 27 CLX 28 3 29 X=Y? 30 GTO zz (label with steps when X=3) 31 CLX 32 4 33 X=Y? 34 GTO ww (label with steps when X=4) 35 ... . . nn LBL xx (steps when X=1) . . .``` If you only have options for 1, 2, 3 or 4, you can eliminate steps 31 to 34; like this: ``` (first program steps) . 19 PROMPT (you input your control # here) 20 1 21 X=Y? 22 GTO xx (label with steps when X=1) 23 CLX 24 2 25 X=Y? 26 GTO yy (label with steps when X=2) 27 CLX 28 3 29 X=Y? 30 GTO zz (label with steps when X=3) (steps when X=4) . . RTN nn LBL xx (steps when X=1) . . .``` If you still need help OR want to know other possibilities and techniques, post your specific problem or e-mail me directly. Best regards. ▼ Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 10-01-2002, 10:12 AM Just to add my e-mail address I forgot when rewriting the post. Cheers.

 Possibly Related Threads... Thread Author Replies Views Last Post HP50g: Writing a function that returns a function Chris de Castro 2 711 12-10-2013, 06:49 PM Last Post: Han Implement 'AND' function with 'XOR' function. tal 4 510 12-13-2000, 05:55 AM Last Post: Steve (Australia)

Forum Jump: