Hello again, I have decided to start from scratch on the code I mentioned before. I am somewhat close to my answer I believe, I just can't get the entire thing to loop over again. Could someone look over it and find my error?
Just to remind everyone, I am trying to find how many terms of a series you need to use before you get the approximation p of Pi, where:
a) p = 3.0
b) p = 3.1
c) p = 3.14
d) p = 3.141
e) p = 3.1415
f) p = 3.14159
The series is 4 X (1 - 1/3 + 1/5 - 1/7 + 1/9 + 1/11 - 1/13...)
Edit: ROFL! I'm an idiot, i put finish is greater than 6... where as I want it to be less than. I appologize for that waste of time, I make stuipid mistakes with < and > signs all the time.
using namespace std;
double pi= 3.14195;
double a = 1, p = 1;
double n = 3, t = 0, sign = -1;
bool check = true;
int h = 0, finish = 0;
a += sign*(1.0/(n));
sign = -sign;
cout << a << " " << t << " " << n << " " << endl;
if (a*4 >= pi-(1*pow(10,-p)) && a*4 <= pi + (1*pow(10,-p)))
check = false;
cout << a*4 << " " << t << endl;
t = 0;
a = 1;
check = true;
while (finish < 6);
2nd Edit: It seems to calculate through the first time but it doesn't seem to calculate it anymore the second time. I made some changes to the code and am replacing the old code with what I have so far.
Just to be clear, what I am doing is trying to make it estimate how many times it takes till it is equal to 3.0 + or - .1, then displaying the number (which I need to fix as well) and how many times it needed to run the test before it got within that parameter. Then it tests for 3.1 with + or - .01 and displayed that and so forth until it reaches 3.14195
3rd Edit: Figured out why it wasn't repeated, had to set check back to true. If anyone has any advice to help me refine this code, I am open to it. I am not very experieneced as of yet with coding, so all advice/critisim/whatever is welcome.