title: how to get the last value of array after the if statement have been satisfied
body: <p>This is what I have so far. My problem is that the iteration function returns the first value of the array. I want it to return the last value after the if statement is satisfied.</p>
  
  <p>This is solving equation using the <a href="http://en.wikipedia.org/wiki/False_position_method" rel="nofollow">False Position Method</a></p>
  
  <pre><code># include &lt;iostream&gt;
  using namespace std;
  
  double iteration(double u, double l);
  double f (double x);
  inline bool closerlimit(double u, double l);
  
  double e;
  void main()
  {   
      cout &lt;&lt; "Enter the upper Limit: " &lt;&lt;endl;
      double ul;
      cin &gt;&gt; ul;
  
      cout &lt;&lt; "Enter The lower Limit: " &lt;&lt;endl;
      double ll;
      cin &gt;&gt; ll;
  
      cout&lt;&lt;"enter level of error: "&lt;&lt;endl;
      cin&gt;&gt;e;
  
      double r;
      r=iteration(ul,ll);
      cout&lt;&lt;"root is : "&lt;&lt; r&lt;&lt;endl;
  }
  
  double f(double x)
  {
      return exp(x)+5*x;
  }
  
  // Evaluating the closer limit to the root
  // to make sure that the closer limit is the
  // one that moves and the other one is fixed
  inline bool closerlimit(double u, double l)
  {
      return fabs(f(u)) &gt; fabs(f(l));
  }
  </code></pre>
  
  <p>This is my iteration function. It only returns the first value of the array. I want it so that after the if statement is satisfied, this function will return the latest value of the root array.</p>
  
  <pre><code>double iteration(double u, double l)
  {
      double root[100], re=0;
      for (int i=0; i&lt;=20; i++)
      {
          {   
              root[i] = u - ((f(u)*(l-u)) / (f(l)-f(u)));
              if (closerlimit(u,l))
                  l = root[i];
              else
                  u = root[i];
  
              double re=0;
              re=abs((root[i]-root[i-1])/root[i])*100;
  
              if (re&lt;=e) {break;}
          }
          cout&lt;&lt;"r = "&lt;&lt;root[i]&lt;&lt;endl;
          cout&lt;&lt;"re = "&lt;&lt;re&lt;&lt;endl;
  
          return (root[i]);
      }
      return 0;
  }
  </code></pre>