The problem is that everytime I run the compile program the output appears to be 1+0+0+0+0....all the way to infinity (I have to manually close the command prompt window).
I've looked over the code and can't seem to pinpoint what's causing this to happen. I'd be really grateful if someone could help me
The line ans=((-1)^(i))*(x^(2*i))/factorial(2*i); isn't doing what you think it is doing. You're trying to use '^' to rasie a number to the power of i but '^' is actually a XOR Bitwise operator.
You should use the <cmath> library and use the power function.