loop issue-Solved - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: loop issue-Solved (/thread-20091.html) |
loop issue-Solved - Amer7 - 06-15-2023 07:24 PM Hi, I'm having an issue writing. I need a loop that will compare if the number is >360, then it will subtract -360, then compare if the number is greater than 180 if it is then -180, else +180; Code: EXPORT numbers() -I use a while loop to make it subtract -360 when the number is greater than 360 Then I compare the number IF its >=180 then -180, else +180. But it's not working WHILE M0(i+1,2)>360 DO /// While its >360 subtract -360 M0(i+1,2):=M0(i+1,2)-360; ---- Memorize it IF M0(i+1,2)>=180 THEN ----- Compare if the memorized value is>=180 M0(i+1,2):=M0(i+1,2)-180; ------ THEN -180 ELSE IF M0(i+1,2)<180 THEN -----If the memorized value vas <180 M0(i+1,2):=M0(i+1,2)+180; ADD +180 END; END; END; Example Result The program does this: 71+320= Compares it the correct result should be 211 and it is Next row, 211+10=231 compare it, the result should be 51(231>180 then 231-180=51) next row, 51+20=71 compare it, result should be 251(71<180 then 71+180=251)... EDIT SOLUTION Code: EXPORT numbers() RE: loop issue-Solved - HPCarnace - 06-18-2023 02:03 PM Isn't it easier to use the division algorithm?, that is, take the remainder of the division of the sum of angles with 90 degrees: irem(71+320+10+20+171,90) returns 52 RE: loop issue-Solved - Amer7 - 06-25-2023 12:32 AM (06-18-2023 02:03 PM)HPCarnace Wrote: Isn't it easier to use the division algorithm?, that is, take the remainder of the division of the sum of angles with 90 degrees: irem(71+320+10+20+171,90) returns 52 probably? This is the first time I hear about division algorithm |