Throw some tracing messages into your code to track the numbers to figure out the solution.
Also... I suggest switching these loops over to for loops. It would be quite a bit more readable.
Code:
//The program checks to see how many parameters it takes to near Pi using the equation 4X(1-1/3+1/5-1/7+1/9-1/11....)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double pi = 3.14195;
double a = 1, p = 1;
double n = 3, sign = -1;
bool check = true;
int finish = 0, t = 0;
do
{
cout << "p is " << p << '\n';
while (check)
{
a += sign*(1.0/(n)); //the equation
sign = -sign; // reversing the signs
t++; // counting how many parameters are needed to near Pi
n+= 2;
cout << "a * 4 " << a * 4 << '\n';
cout << "pi + 1 * pow(10, -(p+1))" << pi + 1 * pow(10, -(p+1)) << '\n';
cout << "pi - 1 * pow(10, -(p+1))" << pi - 1 * pow(10, -(p+1)) << '\n' << endl;
if (a*4 <= pi + 1*(pow(10,-(p+1))) && a*4 >= pi - 1*(pow(10, -(p+1)))) //checking if it is close enough to Pi
check = false; //breaking loop if it is close enough to Pi
}
cout << fixed << setprecision(p);
cout << a*4 << " " << t << endl;
finish++; // adding 1 for each loop completed up to the limit of 6
p++; //adding 1 to the power and precision decimal places
t = 0; //reseting counter
a = 1; //reseting a
check = true; //switching check back to true to loop while again
}while(finish < 6);
return 0;
}
Code:
a * 4 3.13118
pi + 1 * pow(10, -(p+1))3.15195
pi - 1 * pow(10, -(p+1))3.13195
a * 4 3.1519
pi + 1 * pow(10, -(p+1))3.15195
pi - 1 * pow(10, -(p+1))3.13195
3.2 96
p is 2.0
a * 4 4.0
pi + 1 * pow(10, -(p+1))3.1
pi - 1 * pow(10, -(p+1))3.1
a * 4 4.0
pi + 1 * pow(10, -(p+1))3.1
pi - 1 * pow(10, -(p+1))3.1
a * 4 4.0
pi + 1 * pow(10, -(p+1))3.1
pi - 1 * pow(10, -(p+1))3.1
a * 4 4.0
pi + 1 * pow(10, -(p+1))3.1
pi - 1 * pow(10, -(p+1))3.1
The value of a is not changing appreciably, because you are forgetting to reset the value of n to 3 at the start of each loop.