Executed the following code from a book on C I'm reading:
/*Function to calculate the absolute value of a number
using the Newton-Raphson Method */
#include <stdio.h>
float absoluteValue(float x)
{
if (x < 0)
x = -x;
return (x);
}
//Function to compute the square root of a number
float squareRoot(float x)
{
const float epsilon = .00001;
float guess = 1.0;
while (absoluteValue(guess * guess - x) >= epsilon)
guess = (x / guess + guess) / 2.0;
return guess;
}
int main(void)
{
printf("squareRoot(2.0) = %f\n", squareRoot(2.0));
printf("squareRoot(144.0) = &f\n", squareRoot(144.0));
printf("squareRoot(17.5) = %f\n", squareRoot(17.5));
return 0;
}
The square root of 144.0 is showing up as &f and of course it should be 12.000000. What does "&f" mean and why is it doing that? How can I get it to display correctly?
Also, when debugging (I'm sure you get this all the time) all I can see is hex for the value of my variables. I searched and read the tutorials and followed the instructions but all I still see is hex for values. I don't know what I'm doing wrong because just a few weeks ago I followed the instructions when using the debugger and I wasn't seeing hex values but source code values. If someone can give me a link to a past post with thorough instructions I would appreciate it.