Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
1 - Rearrange the code: Open stdin, read all parameters, close stdin, then process the parameters. 2 - Consider adding some validation to the parameters. 3 - Add an explanation of the magic number ...
Answer
#2: Post edited
- 1 - Rearrange the code: Open stdin, read all parameters, close stdin, then process the parameters.
- 2 - Consider adding some validation to the parameters.
- 3 - Add an explanation of the magic number 6378137 - I had to Google it to find out what it means.
- 4 - Replace $i = 45, $i += 90 and the for statement with:
- <pre>
- for ($i = 45; $i <= 405; $i += 90) {
- </pre>
- Which actually doesn't look right. Is it supposed to be $loop <= 4, which turns into $i = 405? Or should it be < 4 which would have the last $i = 315?
5 - Assign cos($d_rad) and sin($d_rad) to variables outside the loop instead of calculating them repeatedly.
- 1 - Rearrange the code: Open stdin, read all parameters, close stdin, then process the parameters.
- 2 - Consider adding some validation to the parameters.
- 3 - Add an explanation of the magic number 6378137 - I had to Google it to find out what it means.
- 4 - Replace $i = 45, $i += 90 and the for statement with:
- <pre>
- for ($i = 45; $i <= 405; $i += 90) {
- </pre>
- Which actually doesn't look right. Is it supposed to be $loop <= 4, which turns into $i = 405? Or should it be < 4 which would have the last $i = 315?
- 5 - Assign cos($d_rad), sin($d_rad), sin($lat) and cos($lat) to variables outside the loop instead of calculating them repeatedly.
#1: Initial revision
1 - Rearrange the code: Open stdin, read all parameters, close stdin, then process the parameters. 2 - Consider adding some validation to the parameters. 3 - Add an explanation of the magic number 6378137 - I had to Google it to find out what it means. 4 - Replace $i = 45, $i += 90 and the for statement with: <pre> for ($i = 45; $i <= 405; $i += 90) { </pre> Which actually doesn't look right. Is it supposed to be $loop <= 4, which turns into $i = 405? Or should it be < 4 which would have the last $i = 315? 5 - Assign cos($d_rad) and sin($d_rad) to variables outside the loop instead of calculating them repeatedly.