I'm having problems with an error saying "invalid operands" for the line "m= a[median]+a[median-1];"
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void median(DollarAmount a[], int size){ // calculates the median of the array
int median;
if(size%2==!0){
median= size/2;
cout << "The median is " << a[median] <<endl;
}
else{
median= size/2;
DollarAmount m;
m= a[median]+a[median-1];
m= m/2;
cout << "The median is " << m <<endl;
}
}
That line contains four operators:
* op- in median - 1. Integers, should not error.
* op[], array member indexing. Twice. Should not error.
* op= in m = result of expression. DollarAmount should have op= by default, unless you have prevented it.
* op+. How do you add DollarAmounts?
Overall, why can't you post the actual error message and save everybody's time?
I used the overload operators and fixed the "invalid operands" error, but now I have a linking error that I have difficulty fixing. I'll post my program below