Hey, i am trying to write a program that will evaluate n!/(k!(n-k)!)
right now i am just trying to get the basic formula without the factorials to work ( i can just do a function call later and get the actual values) but no luck. all the variables have values but im still outputting 0....
here is my code
#include <iostream>
using namespace std;
int factorial (int); //function prototype or declaration
int main()
{
int n1, n2, result, counter, n(0), k(0), partialanswer, partialdenom, numerator, denominator, answer;
cout<<"Please enter two positive integer values less than 15. "<<endl;
cin>>n1;
cin>>n2;
/* while (n1 < 1 || n1 >15)
{
cout<<"You entered an incorrect integer value!"<<endl;
cout<<"Please enter a positive integer value less than 15. "<<endl;
cin>>n1;
cin>>n2;
}
//result = factorial(Q);
///result = partialanswer;
//cout<< "The factorial of "<<n1 <<" write out the rest "<<result<<"."<<endl;
*/
partialdenom = n1-n2;
denominator = n2 * partialdenom;
answer = n1 / denominator;
//factorial = (n / (k(n-k)));
// result = answer;
cout<< "The factorial of "<<n1 <<"!/"<< n2 <<"!("<< n1 << "!-" << n2 << "!) is "<<answer<< "."<<endl;
cout << denominator << endl;
cout << n1 << endl;
cout << n2 << endl;
cout << answer << endl;
return 0;
}
any ideas on why this is happening?
thanks