I'm having trouble getting a recursion template reduceArray() function to divided elements in an array. I have +,-, and * working fine, but division is not working for me. The function should take the given elements and divide as follows ((((4/2)/7)/1)/9)
Here's my code...any tips?
#include<iostream>
using namespace std;
template<typename T>
T reduceArray(T myArray[], int size, char op)
{
if(size < 0 && op == '/')
return 1;
else
if(size == 0)
return myArray[size]/reduceArray(myArray, size-1, op);
else
return reduceArray(myArray, size-1, op)/myArray[size];
}
int main()
{
int ARRAY_CAP = 5;
int intArray[] = {4,2,7,1,9}; // +23 -15 *504 /.0317460317
char op;
cout << "Enter +,-,*, or / to perform one of the mathematical operations on an array of ints: ";
cin >> op;
cout << reduceArray(intArray, ARRAY_CAP-1, op) << endl;
system("pause");
return 0;
}