Post Reply 
loop issue-Solved
06-15-2023, 07:24 PM (This post was last modified: 06-15-2023 08:55 PM by Amer7.)
Post: #1
loop issue-Solved
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()

BEGIN
LOCAL n1,i,c,b;
INPUT({n1},"numbers", {"number"});
Local Rr2,i,Rr3;
i:=1;
c:=n1;
WHILE i<=c DO
M0(i+1,2):=M0(i,2)+M0(i+1,1);


WHILE M0(i+1,2)>360 DO
M0(i+1,2):=M0(i+1,2)-360;
IF M0(i+1,2)>=180 THEN
M0(i+1,2):=M0(i+1,2)-180;
ELSE IF M0(i+1,2)<180 THEN
M0(i+1,2):=M0(i+1,2)+180;



END;
END;
END;

i:=i+1;

END;

EDITMAT(M0,"m0-mat");




END;

-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
[Image: attachment.php?aid=12235]

Result

[Image: attachment.php?aid=12236]

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()

BEGIN
LOCAL n1,i,c,b;
INPUT({n1},"numbers", {"number"});
Local Rr2,i,Rr3;
i:=1;
c:=n1;
WHILE i<=c DO
M0(i+1,2):=M0(i,2)+M0(i+1,1);


WHILE M0(i+1,2)>360 DO
M0(i+1,2):=M0(i+1,2)-360;



END;
IF M0(i+1,2)>=180 THEN
M0(i+1,2):=M0(i+1,2)-180

ELSE 
M0(i+1,2):=M0(i+1,2)+180;

END;
i:=i+1;

END;

EDITMAT(M0,"m0-mat");




END;


Attached File(s) Thumbnail(s)
       
Find all posts by this user
Quote this message in a reply
06-18-2023, 02:03 PM
Post: #2
RE: loop issue-Solved
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
Find all posts by this user
Quote this message in a reply
06-25-2023, 12:32 AM
Post: #3
RE: loop issue-Solved
(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
Find all posts by this user
Quote this message in a reply
Post Reply 




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