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.
In math, when you take the square root of a negative number, you get what's called an "imaginary number". For instance, the square root of -9 is 3i, where "i" is the square root of negative one.
In your code, you took the square root of a negative number when you used "sqrt(number)" for the case in which "number" was negative. That's why you got the weird output - the computer was trying to tell you that you got an imaginary number back.
You can fix it by changing that part of the code to "sqrt(-number)", to flip the negative back to a positive.