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?(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):

#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;

}

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C++ Eulers number truncation

Loading...

Similar Threads - Eulers number truncation | Date |
---|---|

Python Writing numbers on the bars on a seaborn FacetGrid figure | Feb 5, 2018 |

Project Euler solution 3 | Aug 30, 2017 |

Project euler 1 understanding the python code | Jul 16, 2015 |

Project Euler programming challenges: Am I missing something? | Jan 23, 2014 |

Euler method in Fortran | Nov 12, 2013 |

**Physics Forums - The Fusion of Science and Community**