OK, with some help from all of you, I have this working, but I am at a loss as to how to display the number of steps the user asks to show (if they say 10, then every tenth answer displays until the final one) and we need this to display 9 decimal places which I can do with setprecision I think. Then I will have a final answer to display once all is said and done. How in the world would I even begin to get it to display this?
You all rock!
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//function to read inputs from the user test for proper input
//and return the value to main if input is invalid,
//the user will be reprompted for proper input
int validInput (string prompt)
{
int userIn1 = 0;
cin >> userIn1; cout << endl;
while (userIn1 < 1)
{
cout << "Error, cannot be 0 or negative, please try again" << endl;
cin >> userIn1; cout << endl;
}
return userIn1;
}
int main()
{
double pi = 0;
int numCalc = 0;
int userIn1 = 0;
int times = 0;
string userInput = "Please enter the number of terms to use: ";
string userDisplay = "Please enter how often to display steps: ";
cout << "This program calculates the value of PI to varying degrees of accuracy " << endl;
cout << endl;
cout << "The accuracy is based on the desired number of calculations requested by user" << endl;
cout << "The user may also decide the sequence of displayed output during calculations" << endl;
cout << endl << endl;
cout << userInput << endl;
numCalc = validInput (userInput);
cout << userDisplay << endl;
times = validInput (userDisplay);
// Calculating pi/4
for (double n = 1; n <= numCalc; n++)
{
pi += (double) pow(-1, n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << pi << endl;
cout << endl << endl;
system ("PAUSE");
return 0;
}