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.
Avoid std::endendl
Avoid std::end
Avoid std::endl
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;
}