I'm glad that you've got this working now - that's good to hear.
There are a couple of comments I'd like to make, one is to refer back to an earlier post, where I said this:
Note, mathematically the area of the rectangle may be calculated using the value of the function at its left or right edge. One will give an over-estimate, the other an under-estimate. You may get a more accurate result by using the mid-point. Do that by setting the initial value of x to be a + width/2. However, consider that as a refinement for later consideration. |
I don't know whether you've considered or experimented with that.
The second comment is that when a program is more or less complete, in the sense that it is working, could be a good time to review the code, consider whether it can improved, for example by simplifying duplicated code, or by improving the execution time, as well as checking the style, such as consistent indentation and so on.
And not least, I might go back and re-read the original specifications to check that the program achieves precisely what was asked for - I'm not saying this is a problem here, it's just a part of the reviewing process.