#include <iostream>
int main()
{
double x ;
std::cout << "x? " ;
std::cin >> x ;
int n ;
std::cout << "n? " ;
std::cin >> n ;
std::cout << "\nx == " << x << "\ncalculate x - (x^2/2!) + (x^3/3!) - ... "
<< ( n%2 ? '+' : '-' ) << " (x^" << n << '/' << n << "!)\n\n" ;
double term = x ;
constint s = -1 ;
double result = term ;
for( int i = 2 ; i <= n ; ++i )
{
std::cout << std::showpos << term << ' ' ;
term = ( term * s ) / i ;
result += term ;
}
std::cout << term << "\n== " << result << '\n' ;
}
It's more influenced by how I would evaluate polynomials, @tpb. Usually I would follow @JLBorges' term-by-term sum (with the missing x factor) to evaluate power series, because I wouldn't usually know N.