I´m meant to write a code to get an approximate value of Euler´s number or Napier´s (how I´m used to call it) "e".

We know that e = 2.71.. and some more annoying numbers, and that this little guy can be expressed as this :

but, I only manage to get the sum of the first 6 numbers or 8 (because I don´t know how to make it infinite). Anyway, here is the code I tried to run, but the only problem is that when I compile my program, it keeps displaying "2" just that:

Can you guys tell me what I´m doing wrong? And if possible... how can I have an infinite sum of those numbers?

Thanks!

// approximation of euler´s number with infinte sums of the reciprocals of factorials

#include <iostream>

long factorialResult (int number) { // defining my function of factorial

long result = 1 ;

if (number != 0){

do {

result *= number ;

number -- ;

} while (number != 0) ;

} else {

result = 1 ;

}

return result ;

}

using namespace std;

int main (){

int number = 0;

int amount = 0;

float sum = 0 ;

float factor ;

do {

factor = (1/factorialResult(number)) ;

sum += factor;

number ++ ;

amount ++ ;

}while (amount < 13) ;

cout << " Euler´s number is: "<< sum; // this keeps displaying "1" when we know that e = 2.71....

return sum ;

}