Superposed_Cat
- 388
- 5
Hi, just started c++ and I made this program to calculate the value of eulers number. It works in c# but truncates the decimal points as far as I can tell. What am I doing wrong?
Code:
#include <iostream>
using namespace std;
int factorial(int a){
int b=1;
while(a>0){
b=b*a;
a--;
}
return(b);
}
int main()
{
float x=1.0;
for(int i=1;i<25;i++){
x=x+1/factorial(i);
}
cout <<x;
return 0;
}