Implementation of Chord Method written in C++.

```IN
-3
0
0.00001
OUT
X: -1 f(x): -2
X: -2 f(x): -1
X: -2.33333 f(x): -0.222222
X: -2.4 f(x): -0.04
X: -2.41176 f(x): -0.00692042
X: -2.41379 f(x): -0.00118906
X: -2.41414 f(x): -0.000204061
X: -2.4142 f(x): -3.50128e-05
```
```// ? 2018 TheFlyingKeyboard and released under MIT License
// theflyingkeyboard.net
#include <iostream>
#include <math.h>

using namespace std;
static double function(double x);

int main() {
double intervalBegin;
double intervalEnd;
double x;
double precision;

cout << "Enter beginning of interval: ";
cin >> intervalBegin;

cout << "Enter end of interval: ";
cin >> intervalEnd;

cout << "Enter precision of method: ";
cin >> precision;

if (function(intervalBegin) * function(intervalEnd) > 0.0f)
{
cout << "Function has same signs at ends of interval";
return -1;
}

x = (intervalBegin * function(intervalEnd) - intervalEnd * function(intervalBegin)) / (function(intervalEnd) - function(intervalBegin));

while (abs(function(x)) > precision) {
cout << "X: " << x << " f(x): " << function(x) << endl;

if (function(intervalBegin) * function(x) < 0) {
x = (x * function(intervalBegin) - intervalBegin * function(x)) / (function(intervalBegin) - function(x));
}
else {
x = (x * function(intervalEnd) - intervalEnd * function(x)) / (function(intervalEnd) - function(x));
}
}

int a;
cin >> a; //Wait before exiting

return 0;
}

static double function(double x) //x^2 + 2x -1
{
return x * (x + 2) - 1;
}```

C++ Chord Method