//File: pi
//Author: Jesse D
//Date: Feb. 12, 2007
//
//Description: This program uses a loop to estimate pi to the hundreth place.
// The first time pi reaches 3.14, the number of iterations
// it took to reach this value is printed to the screen.
// On each iteration through the loop, the pi estimate is multiplied
// by 100. This value is is then rounded down. If the value of this
// variable is 314 then we know that the estimate is between 3.14 and
// and 3.15 not inlcuding 3.15.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double pi_Estimate = 0; //Holds the value of Pi
double n = 0; //Increment for the loop.
double pi_Temp;
while (!(pi_Temp == 314)) //Jumps out when pi first becomes 3.14
{
//Increment the estimate by the next term .
pi_Estimate += ((pow(-1, n)*4))/((2*n)+1);
pi_Temp = pi_Estimate*100; //Convert the decimal part as required.
pi_Temp = floor(pi_Temp); //Round down.
n+=1;
}
// Output the result.
cout << endl;
cout << "The value for Pi first reaches 3.14 on the " << n << "th iteration" <<< endl;
return 0;
}