// Program Template
#include <iostream>
usingnamespace std;
//Function Prototypes
bool runAgain(void);
double piCalc(int n);
int main() {
int n = 10;
do {
while (n <= 100000) {
cout << "calculatePi(" << n << ")" << " : " << piCalc(n) << endl;
n = n + 10;
}
} while (runAgain());
cout << "Pi:" << piCalc(n);
return(0);
}
// Function Implementation
bool runAgain(void) {
char userResponse;
cout << "\nWould you like to run again (y or n): ";
cin >> userResponse;
cin.ignore(); // to clean up the input stream
if (userResponse == 'y' || userResponse == 'Y')
return(true);
return(false);
}
double piCalc(int n)
{
double sum = 4.0;
double pi;
for (int i = 1; i < n; i++) {
i = pow(-1, i);
pi = 4.0 * (i) / (2.0 * i + 1.0);
sum = sum - pi;
return sum;
}
}