Hey guys. I'm currently working on a project that will ask for a number, and by using a function, will output the square root of the number. The catch is that:
1. If the user enters a negative number, the output will yield the number as if it was a positive, only with a negative.
i.e) -sqrt(4) = -2
Mine outputs -1.#IND
Also, if the user enters a 0, the loop will stop processing. Mine keeps going through the loop and for some reason ignoring the while statement at the end.
Here's my code:
#include <iostream> #include <cmath> using namespace std; double weirdSquareRoot(double number) { double result = sqrt(number); return result; } int main() { double value; do { cout << "Enter a number (a double): "; cin >> value; cin.ignore(); double answer = weirdSquareRoot(value); cout << "The square root is " << answer << endl; } while (value != '0'); }
I appreciate any help