int _tmain(int argc, _TCHAR* argv[])
{
int numberOfTerms;
double sumOfTerms = 0, pi;
char repeat;
do{
cout << "Enter number of terms that should be considered in calculation of pi: ";
cin >> numberOfTerms;
for(int i = 0; i <= numberOfTerms - 1; i++){
sumOfTerms += (-1)^i / (2*i-1);
}
pi = 4 * sumOfTerms;
cout << "*******************************************************" << endl;
cout << "Considering " << numberOfTerms << " terms, the value of pi is: " << pi << endl;
cout << "Do you want to repeat this program? (enter y to repeat): ";
cin >> repeat;
}while(repeat == 'y');
return 0;
} |