0

can someone show me how to code the median if it is an even number

```
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void Fill_Array(double Size[], int& count);
void Print_Array(double Size[], int count);
double Calc_Average(double Size[], int count);
void Sort(double Size[], int count);
void Swap(double& v1, double& v2);
double index_of_smallest(const double Size[], int start_index, int number_used);
double Calc_Median(int count, double Size[]);
void Print_Array_and_Calculations(double median, double average, int count, double Size[]);
const int MAX_SIZE = 100;
int main()
{
ifstream in_size;
int count;
int numbers_used = 0;
int small_index;
double Size[MAX_SIZE];
double median = 0.0;
double average = 0.0;
Fill_Array(Size, count);
Print_Array(Size, count);
small_index = index_of_smallest(Size, count, numbers_used);
average = Calc_Average(Size, count);
Sort(Size, count);
median = Calc_Median(count, Size);
Print_Array_and_Calculations(median, average, count, Size);
in_size.close();
return 0;
}
void Fill_Array(double Size[], int& count)
{
double size;
ifstream in_size;
string text_file;
cout << "Enter the file to read in: ";
getline(cin, text_file);
cout << "The numbers in the array are:" << endl << endl;
in_size.open (text_file.c_str ());
if(in_size.fail())
{
cerr << "Error opening file" << endl;
exit(1);
}
count = 0;
in_size >> size;
while((!in_size.eof()) && (count <= MAX_SIZE))
{
Size[count] = size;
count++;
in_size >> size;
}
in_size.close();
}
void Print_Array(double Size[], int count)
{
int tempcount = 1;
for(int i = 0; i < count; ++i)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
cout << Size[i] << " ";
if (tempcount == 4)
{
cout << endl;
tempcount = 1;
}
else
tempcount++;
}
}
double Calc_Average(double Size[], int count)
{
double total = 0.0;
double average = 0.0;
for (int i = 0; i < count; i++)
{
total = total + Size[i];
}
average = double(total) / count;
return average;
}
void Sort(double Size[], int count)
{
int index_of_next_smallest;
for (int index = 0; index < count - 1; index++)
{
index_of_next_smallest = index_of_smallest(Size, index, count);
Swap(Size[index], Size[index_of_next_smallest]);
}
}
void Swap(double& v1, double& v2)
{
double temp;
temp = v1;
v1 = v2;
v2 = temp;
}
double index_of_smallest(const double Size[], int start_index, int number_used)
{
double min = Size[start_index],
index_of_min = start_index;
for (int index = start_index + 1; index < number_used; index++)
if(Size[index] < min)
{
min = Size[index];
index_of_min = index;
}
return index_of_min;
}
double Calc_Median(int count, double Size[])
{
double median = 0.0;
double average_median = 0.0;
median = Size[ count / 2 ];
return (median);
}
void Print_Array_and_Calculations(double median, double average, int count, double Size[])
{
cout << endl << endl << endl << "The numbers in the array are:" << endl << endl;
Print_Array(Size, count);
cout << endl << endl << endl<< "The average of the numbers is " << average;
cout << endl << "The median of the numbers is " << median;
cout << endl << endl;
}
```