Hi everyone,

My code works out the following equation (from the algorithm on this page: http://williams.best.vwh.net/sunrise...lgorithm.htm):

L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634

...the result of this equation has to be between 0 and 360, and the algorithm says that

"L potentially needs to be adjusted into the range [0,360) by adding/subtracting 360"

At the moment, I have the following code:

This aims to add 360 if L is negative, and to subtract 360 if it is greater than 360, which (unless the answer is -360 > L > 360), should put it between 0 and 360. However, I am getting different values from my program and my calculator when I do it myself, and I think I am right, so what is my program doing wrong? Does the code above work for putting the answer between 0 and 360?Code:L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634; if (L < 0) { L = L + 360; } else if (L > 360) { L = L - 360; } else { L = L + 0; } //Rest of program.

The value of M in both the program and my calculation is 81.7209, and my program puts L at 4.43216, but I get 6.2566 (which I think is correct).

Thanks a lot!