Ah, I see now.

But, like I said before, the most apparent problem is the need for larger variables that can hold all that data.

To demonstrate:

Here, I did a simple find and replace on all your ints and made them unsigned longs. Same as a long, only twice as big because it can only hold positive numbers. AFAIK, this is the largest int data type possible.

**Code:**

#include <iostream>

using namespace std;

//prototype functions

unsigned long factorial(unsigned long);

unsigned long powerFunction ( unsigned long, unsigned long);

unsigned long permutationWithoutRepetition(unsigned long,unsigned long);

unsigned long combinationsWithRepetition( unsigned long, unsigned long);

unsigned long combinationsNoRepetitions( unsigned long, unsigned long);

int main()

{

unsigned long input1, input2;

cout<<"First number."<<endl;

cin>>input1;

cout<<"Second number."<<endl;

cin>>input2;

//Check input to ensure second number is larger than first

while (input1<=input2&&input1>0){

cout<<"The second number must be smaller than the first number. Please enter the \nsecond number."<<endl;

cin>>input2;}

cout<<"The number factorial is "<<factorial(input1)<<endl;

//function call for permutations without repetition

unsigned long permNoReps=permutationWithoutRepetition(input1,input2);

//fucntion call for combination with repetition

unsigned long combWithRep=combinationsWithRepetition(input1,input2);

//function call for combinations without repetition

unsigned long combNoRep=combinationsNoRepetitions(input1,input2);

cout<<"The permutations withy repetitions are "<<powerFunction(input1,input2)<<endl;

cout<<"The permutations without repititions are "<<permNoReps<<endl;

cout<<"The combinations with repetition are "<<combWithRep<<endl;

cout<<"The combinations without repetition are "<<combNoRep;

system ("pause");

return 0;

}

unsigned long factorial ( unsigned long x){

unsigned long total,z;

total=1;

for(z=1;z<=x;z++)

total=total*z;

return total;}

unsigned long powerFunction( unsigned long x, unsigned long y){

unsigned long z=1;

for (unsigned long a=1;a<=y;a++)

{z=z*x;}

return z;}

unsigned long permutationWithoutRepetition( unsigned long x, unsigned long y){

unsigned long tempFactorial=x-y;

unsigned long permNoReps=factorial(x)/factorial(tempFactorial);

return permNoReps;

}

unsigned long combinationsWithRepetition( unsigned long x, unsigned long y){

unsigned long combWithReps=factorial(x+y-1)/(factorial(y)*factorial(x-1));

return combWithReps;

}

unsigned long combinationsNoRepetitions( unsigned long x, unsigned long y){

unsigned long combNoReps=factorial(x)/(factorial(y)*factorial(x-y));

return combNoReps;

}

Now, what you have to realize is that your given calculations are quite possible to do with larger numbers, but it's the factorial function that is giving you the problems. 15 factorial has something like 12 decimal places. 16 factorial is 16 times that. You see how this increases almost exponentially.

A way to make this work is to simplify before you take the factorial.

For example, if you have:

6!/3!

and expand it:

(6*5*4*3*2*1) / (3*2*1)

You can obviously see that 6!/3! is simply equal to (6*5*4)

To put this in code, it could be as simple as:

**Code:**

int input1=6;

int input2=3;

int output=1;

//Find 6! / 3!

for (int i=input2+1; i<=input1; i++)

output*=i;

// here are the steps the output variable goes through with the given inputs:

// initialized to one

//multiplied by 4 (input2+1)

//multiplied by 5

//multiplied by 6

//You can see, this process is equivalent to what we said 6!/3! is: (4*5*6)

Haven't tested that myself, but it looks right.

So I suggest you change your factorial function to take a numerator (call it input1) and a denominator (call that input2) as arguments, and you won't have to be dealing with huge #'s.