Answer:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
char choice;
cout << setprecision(12) << endl;
while(true) {
int sign = 1;
double pi = 0;
cout << "Enter number of terms: ";
long n;
cin >> n;
for(long i = 1; i < n; i += 2) {
pi += sign/(double)i;
sign = -sign;
}
pi *= 4;
cout << "value of pi for n = " << n << " is " << pi << endl;
cout << "Do you want to try again(y or n)? ";
cin >> choice;
if(choice == 'n' || choice == 'N') {
break;
}
}
return 0;
}
Explanation: