This code is complete. However, I need Someone to add comments on what the code is doing for each line. Then I need a UM

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

This code is complete. However, I need Someone to add comments on what the code is doing for each line. Then I need a UM

Post by answerhappygod »

This code is complete. However, I need Someone to add
comments on what the code is doing for each line. Then I need a UML
diagram.
#include <iostream>
using namespace std;
double recursiveSquare(double, double);
int main() {
double x;
cout << "Input a number to find its square root: " <<
endl;
cin >> x;
double answer=recursiveSquare(x, x);
cout << "The sqaure root is " << answer <<
endl;
return 0;
}
double recursiveSquare(double x, double a)
{
double epsilon=0.000001;
double hold;
double divisor;
double level=a*a;
level=level-x;
if(level<0)
{
level=level*-1;
}
if(epsilon >= level)
{
return a;
}
else
{
hold=a*a;
hold=hold+x;
divisor=2*a;
hold=hold/divisor;
a=hold;
return recursiveSquare(x, a);
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply