Write a MAIN function and a FUNCTION to compute the sum of the below series.

((-1)^(n+1)*n!)/(n*n) (from n=1 to infinity)

Within the MAIN function:
. Read a variable EPSILON of type DOUBLE (desired accuracy) from
the standard input.
EPSILON is an extremely small positive number which can be anything
between 1E-06 (10^(-6)) and 1E-12 (10^(-12)).
. EPSILON value will be passed to the FUNCTION as an argument.
Within the FUNCTION:
. In a do-while loop:
. Continue adding up the terms until |Sn+1 - Sn| < EPSILON.
. Sn is the sum of the first n-terms.
. Sn+1 is the sum of the first (n+1)-terms.
When the desired accuracy EPSILON is reached print the SUM and the number
of TERMS added to the sum.

See response to your earlier post.

http://www.jiskha.com/display.cgi?id=1331322048

To compute the sum of the given series and implement the required functions, you can follow these steps:

1. Define the main function:
```
#include <iostream>

// Function to compute the sum of the series.
double computeSeries(double epsilon);

int main() {
double epsilon;
std::cout << "Enter desired accuracy (EPSILON): ";
std::cin >> epsilon;

computeSeries(epsilon);

return 0;
}
```

2. Define the `computeSeries` function to calculate the sum:
```
#include <cmath>

double computeSeries(double epsilon) {
double sum = 0.0;
double term = 0.0;
int n = 1;

do {
// Calculate the term value using the given formula.
term = std::pow(-1, (n + 1)) * tgamma(n + 1) / (n * n);

// Add the term to the sum.
sum += term;

// Increment the number of terms.
n++;
} while (std::abs(term) >= epsilon);

std::cout << "Sum: " << sum << std::endl;
std::cout << "Number of terms added: " << (n - 1) << std::endl;

return sum;
}
```

Let's break it down:

- In the main function, we read the desired accuracy (`EPSILON`) from the user and pass it as an argument to the `computeSeries` function.
- The `computeSeries` function initializes the sum and term to zero, and the variable `n` to 1, which represents the number of terms.
- Inside the do-while loop, it calculates each term of the series using the given formula and adds it to the sum. It then increments `n`.
- The loop continues until the absolute difference between two consecutive terms is less than the desired accuracy (`epsilon`).
- Finally, it prints the sum and the number of terms added.

Note: The `tgamma` function from the `cmath` library is used to calculate the factorial of `n+1` (`tgamma(n+1)`). Make sure to include the necessary header files (`iostream` and `cmath`).

Now you can compile and run the program, and enter the desired accuracy (EPSILON) when prompted. The program will compute the sum of the series and display the result along with the number of terms added.