0

Hi again,

My logic is not too good. I am supposed to get this function to be used twice for two different inputs calling the "strings" from within the function and returning the values to main (perhaps my mistake is attempting to call this program twice??? except that is what the instructor has asked for). I can get that to work, but I am trying to get it so it returns the values input when asked for the correct string. I am having trouble finding a loop that I can use to get it to ask for terms the first time through, then the display otions the second time.... I am VERY good at looping my machine forever, but no luck geting the alternate questions and answers to work.

suggestions?

Thanks,

Cougarclaws.

```
#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 ( )
{
int userIn1 = 0;
int userIn2 = 0;
int count = 0;
int displayCount = 0;
string userInput = "Please enter the number of terms to use: ";
string userDisplay = "Please enter how often to display results: ";
for (int count = 0; count == 0; count++)
if (count == 0)
cout << userInput;
cout << userDisplay;
cin >> userIn1; cout << endl;
while ( userIn1 < 1)
{
cout << "Error, cannot be 0 or negative" << endl;
cout << userInput;
cin >> userIn1; cout << endl;
}
return userIn1;
}
int main()
{
double pi = 0;
int numCalc = 0;
int userIn1 = 0;
int times = 0;
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;
numCalc = validInput ();
times = validInput ();
// Calculating pi/4
for (double n = 1; n <= numCalc; n++)
{
pi += (double) pow(-1, n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << endl << endl;
system ("PAUSE");
return 0;
}
```