I am currently working on a c++ program that computes factorials and I can't get it to work for some reason, i could really use a hint, this is what I have thus far for code:
[code=cpp]
#include<iostre am>
using namespace std;
int n;
int i;
int main()
{
cout << "Enter a positive number:";
cin >> n;
i=n;
while (n > 1 )
{
i=i*(n-1);
n--;
}
cout << i;
return 0;
}
[/code]
the code works until I hit 20, and then it sends me to a negative number. Any ideas how? thanks!
[code=cpp]
#include<iostre am>
using namespace std;
int n;
int i;
int main()
{
cout << "Enter a positive number:";
cin >> n;
i=n;
while (n > 1 )
{
i=i*(n-1);
n--;
}
cout << i;
return 0;
}
[/code]
the code works until I hit 20, and then it sends me to a negative number. Any ideas how? thanks!
Comment