I am trying to take 2 numbers that have been input into 2 arrays, and place their product into a third array.
My multiply function is way off. It is only multiplying the first pair of numbers. I am not sure where to decrement which variables to make it multiply the entire thing. I'm not sure what you need to see to know where my mistakes are, but I only have the function here...
Will someone please show me how to fix this function?
//******************************************************************************
void multiply(int num1ary[], //Passing in num1 array,
int num2ary[], //num2 array,
int length1, //arrayLength1,
int length2) //and arrayLength2
{
int counter; //Counting numbers to process
int i = 49; //Start at the end of array 1
int j = 49; //Start at the end of array 2
int k = max(length1, length2);//Finds longest number
//(in case longer number isn't the top number)
int carry = 0; //Variable to hold carry value
int productary[50] = {0}; //Array to hold answer
int end = 49; //Product array end position
for (counter = 0; counter <= k; counter++)//While counter is less than or equal to the longest
//length of num1 or num2
{
//Last answer position is set to mod 10 of answer
productary[end] = ((num1ary[i] * num2ary[j]) % 10);
//Variable is set to previous answer/10
carry = (num1ary[i] * num2ary[j]) / 10;
//Next product array position is set to value in carry
productary[end - 1] = carry;
} //Fall out of loop when we have made k calculations
for( int count = 0; count <= k; k--)//While count is less than or equal to the longest
//length of num1 or num2
{
cout << productary[end - k]; //Display the leftmost number
outfile << productary[end - k]; //And work your way to the left
} //Fall out of this loop when all calculations have been made
}//End of function
//******************************************************************************