When I integrate from -a to 0, the sum of rectangles or the sum of trapezoids should be negative right?
My teacher didn't mention anything about restricting user input to [a,b] where a < b. If user inputs b < a, I included a simple swap vars test to prevent the program from integrating, say, from 10 to 0, resulting in negative result. That swap var step doesn't violates $\int_a^b = -\int_b^a$ or does?
Test ran: the simplest function f(x) = x
Better explanation: user chooses a, b and m, the only restriction is that m must be integer and positive.
First time I did (b - a)/m. If b > a, then that value is never negative. Program calculates $\int_0^{10} xdx = 50$ and $\int_{10}^0 xdx = -50$ with trapezoids, with rectangles it gets close, but it's never exact no matter if user inputs m = 1 trillion.
If user inputs 10 and 0, the result is -50. The guy who is going to grade the programs said "area cannot be negative, do |a - b|/m". Tried that, but for 10 to 0 case, program calculated 150 (it calculated the area between 10 to 20, because it started at 10 and moved to the right, to 20, rather than starting at 10 and going to the left, to 0).
Next attempt, inserted a swap a and b, if b < a (that's before (b - a)/m). Now it calculates $\int_0^{10} xdx = 50$ and $\int_{10}^0 xdx = 50$. I guess, swap should be done after (b - a)/m ? Because the sum of rectangles in this program can only start at "a" and go to the right, I didn't bother adding a second case, to do the sum right to left, starting at "b".