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:
// The Integral
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <stdexcept>
#include <iomanip>
using std::cin; using std::cout;
using std::endl;
int func (int x);
int main ()
{
cout << "Please enter left and right bounds: ";
int left, right;
cin >> left >> right;
cout << "Please enter a # of partitions (>0): ";
int R;
cin >> R;
int width = (right - left) / R;
int total = 0;
for (int i = 0; i < R; ++i) {
total += func(left + width*i);
}
cout << "The integral is: " << total << endl;
return 0;
}
int func (int x)
{
return x*x;
}