Help - the static_cast< double > is not calculating the value of term and I cannot see what is wrong.
void eConstant::compute()
{
cout << "Enter the desired level of accuracy to calculate the mathematical constant e,
\nmeaning the number of terms in the summation: ";
cin >> accuracy;
validate(accuracy);
setAccuracy(accuracy);
int denominator = 0;
double term = 0;
while (accuracy > 0)
{
if (accuracy == 1)
{
e += 1;
accuracy -= 1;
}
else
{
denominator = nFactorial(accuracy - 1);
term = static_cast< double >((numerator/denominator));
e += term;
accuracy -= 1;
}
}
}
int eConstant::nFactorial(int position)
{
int value = 0;
int n = position;
factorial = 1;
int factor = 0;
do
{
factor = n - value;
factorial *= factor;
value += 1;
} while (value < position);
return factorial;
}