ok the purpose of the program is return the square root value.
heres what i got so far.
Quote
#include <iostream.h>
#include <fstream.h>
double absValue(double x)
{
if (x<0)
return -x;
else
return x;
}
double squareRoot(double x)
{
double y;
y=x;
while (absValue(y*y)>.0001){ // why y*y, i don't understand this part
//seems like it will make it into an infinite
//loop
y = (y+x/y);
}
return y;
}
int main()
{
double x;
cin>>x;
cout<< squareRoot(x);
cin>>x; // to pause window from closing
}
#include <fstream.h>
double absValue(double x)
{
if (x<0)
return -x;
else
return x;
}
double squareRoot(double x)
{
double y;
y=x;
while (absValue(y*y)>.0001){ // why y*y, i don't understand this part
//seems like it will make it into an infinite
//loop
y = (y+x/y);
}
return y;
}
int main()
{
double x;
cin>>x;
cout<< squareRoot(x);
cin>>x; // to pause window from closing
}
The absolute value function work without any problem, but i don't understand the squareRoot function. it looks like the Babylonian method for square root, but then again i am not sure. any help will be appreciated.


Sign In
Create Account

Back to top









