Hi all,
I have tried this several ways. I need to get the user function to return userIn1 to main. I don't need to read anything from the call to the function, but if I leave out paraneters, it really does not work. My original issue was that the string value and print outputs are not showing up. I believe this is because of my inability to fix the function. I will have to use the function for this assignment twice, so if there is more I need to do to get that to work (once built for displayCount), please guide me. Thanks for all the help in advance!
I have not even started the PI accuracy side of this yet, so since I know this is a common HW assignment, any help with understanding how the formula would get written is appreciated as well.
#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 repormpted for proper input
int validInput (int)
{
string userInput = "Please enter the number of terms to use: ";
int userIn1 = 0;
int displayCount = 0;
cout << userInput;
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()
{
int numCalc = 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 (userIn1);
cout << endl << endl;
system ("PAUSE");
return 0;
}