Factorial Problem [Beginner]

Here's the problem: everything works FINE, until you type in 13 or more. Please explain it to me :/

Code is in here:
http://www.cplusplus.com/forum/general/33968/#msg186730
An int is too small to hold that big a number (13!). Try "long int" for the return value of the function.
Still doesn't work mate.
What value do you get for 13!? I was getting something like 1932053304, but when I changed int to long int I got 6227020800.
Could you please paste the code in here? I've changed everything to long int, and still get 1932...... answer. Thanks!

#include <iostream>
#include <string>

long int factor( int num );

long int factor( int num ) {
if (num == 1) {
return (1);
}
else
return num * factor (num - 1);
}


int main(int argc, const char * argv[]) {
long int fact;
int num;
std::string num_as_string;
std::cout << "\n Enter an integer to take the factorial of:\n ";
std::cin >> num_as_string;
num = stoi(num_as_string);
fact = factor(num);
std::cout << num << "! is " << fact << "\n";
return 0;
}
Topic archived. No new replies allowed.