I have been trying to write a Newton's Method program for the square root of a number and have been failing miserably... can anyone help me i have this so far?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x1;
double y;
double x0;
cout << "Enter a value to be square rooted: " << endl;
cin >> y;
x0 = (y/4);
cout << x0 << endl;
constdouble ACCURACY=0.001;
double lower, upper, guess;
if (number < 1)
{
lower = number;
upper = 1;
}
else
{
lower = 1;
upper = number;
}
while ((upper-lower) > ACCURACY)
{
guess = (lower + upper)/2;
if(guess*guess > number)
upper =guess;
else
lower = guess;
}
return (lower + upper)/2;
}
/*enter a number to take the sqrt of
612
24.7387 is the square root of 612
Process returned 0 (0x0) execution time : 4.766 s
Press any key to continue.
*/