Hi, I've been using C++ to calculate the approx area under a graph with trapezium rule.
The graph I want to calculate the area under is y=1/x with lower limit "a" and upper limit "b".
However when I put values in, the answer turns out to be far off.
Here is my c++ list. Someone please identify the problem:
#include <iostream>
using namespace std;
int main ()
{
int n,k; // n represents the number of strips
float a, b, p, Sn, I;
cout << "insert lower limit";
cin >> a;
cout << "insert upper limit";
cin >> b;
cout << "insert number of strips";
cin >> n;
p = (b-a)/n;
for(k=1; k<n; k++)
{
Sn =+ 2/(a + k*p);
}
Sn =+ ((1/a) + (1/b));
I = (p/2)*Sn;
cout << I << endl;
return 0;
}
What is this?? Sn =+ 2*(a + k*p);
I'm thinking in particular about the =+ part
How are you expecting that to work (I'm checking on
your knowledge of c++ operators).