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