Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

If you do need to compute a hypotenuse, consider using std::hypot instead of re-implementing it yourself. In the worst case, this will just be a thoroughly tested and debugged version of the code you'd write on your own. In a better case, it might use a different algorithm to compute the result. For example, you might have a case where both your \$\Delta x\$ and \$\Delta y\$ are within range and the final answer would be within range, but \$\Delta x^2 + \Delta y^2\$ is out of range. In this case, the simplistic approach will overflow, but some others others won't. Depending on your hardware and/or required precision, alternatives may also be faster.

If you do need to compute a hypotenuse, consider using std::hypot instead of re-implementing it yourself. In the worst case, this will just be a thoroughly tested and debugged version of the code you'd write on your own. In a better case, it might use a different algorithm to compute the result. For example, you might have a case where both your \$\Delta x\$ and \$\Delta y\$ are within range and the final answer would be within range, but \$\Delta x^2 + \Delta y^2\$ is out of range. In this case, the simplistic approach will overflow, but some others won't. Depending on your hardware and/or required precision, alternatives may also be faster.

If you do need to compute a hypotenuse, consider using std::hypot instead of re-implementing it yourself. In the worst case, this will just be a thoroughly tested and debugged version of the code you'd write on your own. In a better case, it might use a different algorithm to compute the result. For example, you might have a case where both your \$\Delta x\$ and \$\Delta y\$ are within range and the final answer would be within range, but \$\Delta x^2 + \Delta y^2\$ is out of range. In this case, the simplistic approach will overflow, but some others won't. Depending on your hardware and/or required precision, alternatives may also be faster.

typo - std::end vs std::endl
Source Link
Mat
  • 3k
  • 1
  • 22
  • 25

Avoid std::endendl

Avoid std::end

Avoid std::endl

edited body
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 144
double get_value(char const &prompt*prompt) { 
 double value;
 std::cout << "\n" << prompt;
 std::cin >> value;
 return value;
}
double get_value(char const &prompt) { 
 double value;
 std::cout << "\n" << prompt;
 std::cin >> value;
 return value;
}
double get_value(char const *prompt) { 
 double value;
 std::cout << "\n" << prompt;
 std::cin >> value;
 return value;
}
added 1075 characters in body
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 144
Loading
Source Link
Jerry Coffin
  • 34.1k
  • 4
  • 77
  • 144
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /