# Squareroot help

This is a discussion on Squareroot help within the C++ Programming forums, part of the General Programming Boards category; Hey i'm trying to do a program that returns the answer to a squareroot!!! Please help...the answer I keep on ...

1. ## Squareroot help

Code:
```#include <iostream>
using namespace std;

float Squareroot(float x);

int main() {
float numberA;
float squrtquotient;

cout << "Hey maya here's your squareroot!" << endl;
cout << "Enter your number to squareroot and you'll be off into happyland!\n\t" ;
cin >> numberA;
squrtquotient = Squareroot(numberA);
cout << "\t" << squrtquotient << endl;
cout << "\t\tWOWSERS!!!!!!!!!!!!!!" << endl;
cin.get();
return 0;

}

float Squareroot(float x) {
cin.get();
return (x/x) ;
}```

2. Code:
`return (x/x);`

3. If you want to roll your own square root method, do a search on Newton-Raphson root-finding.

If you just want to get the square root, include the header <cmath>, and call the std::sqrt function.

4. x/x will always return 1, unless x is zero (in which case, the behaviour is implementation defined).

Why not use the std::sqrt() function, which is declared in the <cmath>? The only difference is that it accepts a double argument and returns a double ......

5. Originally Posted by MrWizard
Code:
`return (x/x);`
Hehe. Short, sweet, and to the point.

If you have no reason not to use cmath's sqrt(), use it. Otherwise, I'd recommend Newton's iteration. It's a beautiful thing. Like magic.

6. What is Newton's iteration?

7. when someone give you a specific name, this would
be a good time to go to

www.google.com and type that name into search feild,
possibly adding the word "c++" in there somewhere
to possibly narrow the field down.