can someone help me with this problem(factorial)
everything is working fine but when I enter a negative number the program crashes somewhere....but n can be any non-negative number
Here is da code
#include <iostream>
#include <string>
using namespace std;
int fact(int n){
if (n==0)
return 1;
else
return fact(n-1)*n;
}
int main()
{
int number;
char response;
do{
cout<<"Enter number: ";
cin>>number;
cout<<"factorial: "<<fact(number)<<endl;
cout<<"Do you want to continue: ";
cout<<"(Press Y/N)"<<endl;
cin>>response;
}while((response=='y') || (response=='Y'));
system("PAUSE");
return 0;
}