Cauchy Distribution Secant Method C++ RCPP : I am quite new to C++ and RCPP integration. I am required to create a program using C++ with R integration to find the MLE/root of a Cauchy Distribution. 

Below is my code thus far. 

    #include <Rcpp.h> 
    #include <math.h>
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    using namespace Rcpp;


    // [[Rcpp::export]]
    double Cauchy(double x, double y);    //Declare Function
    double Cauchy(double x,double y)    //Define Function
    {
  
    return    1/(M_PI*(1+(pow(x-y,2))));    //write the equation whose roots are 
    to be determined x=chosen y=theta
  
    }


    using namespace std;

    // [[Rcpp::export]]


    int Secant (NumericVector x){
    NumericVector xvector(x) ; //Input of x vector
    double eplison= 0.001; //Threshold
    double a= xvector[3]; //Select starting point
    double b= xvector[4];//Select end point
    double c= 0.0; //initial value for c
    double Theta= 10.6; //median value for theta estimate
    int noofIter= 0; //Iterations
    double error = 0.0; 
  
    if (std::abs(Cauchy(a, Theta)<(std::abs(Cauchy(a, Theta))))){  
 

    do{
  
    a=b;
  
    b=c; 
  
  
    error= (b-(Cauchy(b, Theta)))*((a-b)/(Cauchy(a, Theta)-Cauchy(b, Theta)));
  
    error= Cauchy(c,Theta); 
  
    //return number of iterations
    noofIter++;

  
    for (int i = 0; i < noofIter; i += 1) {
    cout << "The Value is " << c << endl;
    cout << "The Value is " << a << endl;
    cout << "The Value is " << b << endl;
    cout << "The Value is " << Theta << endl;
    }
  
 
    }while (std::abs(error)>eplison);
  
    }
 
  
    cout<<"\nThe root of the equation is occurs at "<<c<<endl;    //print the 
    root
    cout << "The number of iterations is " << noofIter;
    return 0;
    }``



With a few ammendments, the program either goes into a never ending loop or returns a value which is infinitely small. 


My understanding of this mathematics is limited. Therefore any help or correction in that would be greatly appreciated. 

The X vector that we have been given as an output is 

x <- c( 11.262307 , 10.281078 , 10.287090 , 12.734039 ,
         11.731881 , 8.861998 , 12.246509 , 11.244818 ,
         9.696278 , 11.557572 , 11.112531 , 10.550190 ,
         9.018438 , 10.704774 , 9.515617 , 10.003247 ,
         10.278352 , 9.709630 , 10.963905 , 17.314814)

Using previous R code we know that the MLE/Root for this distribution occurs at 10.5935 approx 

Thanks!