Deepest apologies as I'm sure I'm being dumb but I haven't been able to crack this and I have a school deadline coming up :(
this chunk of code is supposed to approximate the number e, by repeating this process:
e = 1 + 1/1! + 1/2! + 1/3! + 1/4! + 1/5! + ...
the user is supposed to specify the amount of iterations with the int e_stop, so that the output would look like this:
1 -> 2 2 -> 2.5 3 -> 2.666.. 4 -> 2.708333..
and so on, but as of right now the output looks like this:
1 -> 2 2 -> 2 3 -> 2 4 -> 2
import java.util.Scanner;
Scanner Case3Scanner = new Scanner(System. in );
System.out.println("Nivel de exactitud? (iteraciones)?");
//e = 1 + 1/1! + 1/2! + 1/3! + 1/4! + 1/5! + ..
int e_stop = Case3Scanner.nextInt();
System.out.println("--------------");
double e_total = 1; //this is the result we will output
double e_divisor = 1; //this is the number we will get the factorial of of
long e_fact = 1; //this is the factorial of e_divisor
for (int e = 1; e <= e_stop; e++) {
//this for-loop should repeat r_stop times.
//this next for-loop should make e_fact equal the factorial of e_divisor
for (int ef = 2; ef <= e_divisor; ef++) {
e_fact *= ef;
}
e_total += 1 / e_fact;
System.out.println(e_total);
e_divisor += 1;
}