0

HI I would like to modify the following function so that it could take any of the operators such as +,-,* or /. I want to know if its possible to do this without having to write bunch of ifs and else to define each of the operators separatly like i did the division one.

```
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];
}
```

..

..

..

What I want to accomplish is this

```
int a=5, b=4;
cout<<calc(a,b,'+');
int calc(int a, int b, char c) {
return a c b; //is there a way such that if c='+' it would add a and b
// if c='-' it would subtract
```