I've written this progarm which looks at 2 arrays then calls a function and returns the median of each array, but I think when I goto call the function the 2nd time it ignores it and just uses the value from the first time i called it....can someone help me out?
#include <iostream.h>
float Median(int *, int);
void main(void)
{
int Odd[] = {1, 2, 3, 4, 5, 6, 7};
int Even[] = {1, 2, 3, 4, 5, 6, 7, 8};
cout << "Median using an odd array: " << Median(Odd, 7) << endl;
cout << "Median using an even array: " << Median(Even, 8) << endl;
}// void main(void)
float Median(int *array, int size)
{
float First = 0, Last = size - 1;
float evenanswer = 0, oddanswer = 0;
int Middle;
Middle = First + (Last - First) / 2;
if ((Middle % 2) != 0)
{
oddanswer = array[Middle];
return oddanswer;
}
else
{
evenanswer = (array[Middle] + array[Middle + 1]);
evenanswer = evenanswer / 2;
return evenanswer;
}
}// void Median(int *, int);