I'm trying to find the square root of a number through this function and it's not very precise. For example, if you enter 496, my output is 22.2711, while my professor's sample output is 22.271057.
I've tried making an int, double, and long double and the answer stays the same.
I can't use setprecision() either because this code must work for any number, so if the square root is 2 then it needs to print as "2" rather than "2.000000".
Here is the function responsible for finding the square root:
long double myInt::squareRoot() {
long double value = 0.0;
value = sqrtl(static_cast<long double>(num));
return value;
}
Thanks in advance for any help!
example:
#include <cmath>
int main {
int number = 496;
long double result = 0.0;
result = sqrtl(static_cast<long double>(number));
cout << result;
output here is 22.2711.