Help with looping etc THANKS ALOT IN ADVANCE

Code Java:

import io.*;
public class count
{
public static void main( String [] args)
{
double x;
x=ConsoleInput.readDouble("Enter x value");
for(int n=0;n<=10;n++)
{
eToTheX(x,n);
}
}
public static void eToTheX(double x, int n)
{
double e=0, nFactorial = 1;
for(int i=2; i <=n; i++)
{
nFactorial *= (double)i;
}
e+=Math.pow(x,(double)n)/nFactorial;
System.out.println("real ex " + Math.exp(x) + " calculated ex " + e);
}
}

ok so my e+= isnt exactly working... it's just not adding e onto itself each time it displays 11 outputs like i want it to but they dont stack so for e.g. its just x^5/5! when i need x^0/0!+..+..x^5/5! so i need it to output 0,(0..+.. 1),(0+1+2),(0+1+2) thats first 4 results i need that up until its 8+9+10 etc which would be 11 results

so basically

http://i53.tinypic.com/15mbnuw.jpg

Re: Help with looping etc THANKS ALOT IN ADVANCE

You're creating a new e variable each time you call the function, so it's going to start over as zero each time.

Re: Help with looping etc THANKS ALOT IN ADVANCE

Quote:

Originally Posted by

**KevinWorkman**
You're creating a new e variable each time you call the function, so it's going to start over as zero each time.

can you please show me how to make it work, i've tried everything =/

Re: Help with looping etc THANKS ALOT IN ADVANCE

You could return the value from that function, then increment another variable with it?