title: C++ Integration Solution using Riemann Sum : Loses validity for greater than 10 partitions
body: <p>In an effort to code the briefest solution I could for an approximation of the integral using Riemann sums, I ran into a strange problem: if the user requested a partition count in excess of 10, the program failed. Any thoughts? Here's the code:</p>
  
  <pre><code>// The Integral
  
  #include &lt;algorithm&gt;
  #include &lt;iomanip&gt;
  #include &lt;ios&gt;
  #include &lt;iostream&gt;
  #include &lt;stdexcept&gt;
  #include &lt;iomanip&gt;
  
  using std::cin;     using std::cout;
  using std::endl;    
  
  int func (int x);
  
  int main () 
  {   
      cout &lt;&lt; "Please enter left and right bounds: ";
  
      int left, right;
      cin &gt;&gt; left &gt;&gt; right;
  
      cout &lt;&lt; "Please enter a # of partitions (&gt;0): ";
  
      int R;
      cin &gt;&gt; R;
  
      int width = (right - left) / R;
      int total = 0;
  
      for (int i = 0; i &lt; R; ++i) {
          total += func(left + width*i);
      }   
  
      cout &lt;&lt; "The integral is: " &lt;&lt; total &lt;&lt; endl;
  
      return 0;
  }
  
  int func (int x) 
  {
      return x*x;
  }
  </code></pre>