long double vs long int
<p>I'm doing a program that calculates the probability of lotteries.
Specification is choose 5 numbers out of 47 and 1 out of 27</p>

<p>So I did the following:</p>

<pre><code>#include &lt;iostream&gt;

long int choose(unsigned n, unsigned k);
long int factorial(unsigned n);

int main(){
    using namespace std;
    long int regularProb, megaProb;
    regularProb = choose(47, 5);
    megaProb = choose(27, 1);
    cout &lt;&lt; "The probability of the correct number is 1 out of " &lt;&lt; (regularProb * megaProb) &lt;&lt; endl;

    return 0;
}

long int choose(unsigned n, unsigned k){    
    return factorial(n) / (factorial(k) * factorial(n-k));
}

long int factorial(unsigned n){
    long int result = 1;
    for (int i=2;i&lt;=n;i++) result *= i;
    return result;
}
</code></pre>

<p>However the program doesn't work. The program calculates for 30 seconds, then gives me <code>Process 4 exited with code -1,073,741,676</code> I have to change all the long int to long double, but that loses precision. Is it because long int is too short for the big values? Though I thought long int nowadays are 64bit? My compiler is g++ win32 (64bit host).</p>
