Need to find a fix to this implicit cast error to get the code to compile. The code is:
// Program calls a method that finds and returns
// the median value in an array
// The median value is the middle value from largest to smallest
// If there are an even number of values, the
// median is the mean of the two middle values
using System;
using static System.Console;
class DebugSeven4
{
static void Main()
{
double[] firstArray = { 10, 9, 2, 3, 5, 6 };
double[] secondArray = { 112, 456, 782 };
double[] thirdArray = { 9, 12, 45, 82, 84, 67, 2, 6 };
WriteLine("The median value of the first array is {0}",
FindMedian(firstArray));
WriteLine("The median value of the second array is {0}",
FindMedian(secondArray));
WriteLine("The median value of the third array is {0}",
FindMedian(thirdArray));
}
private static double FindMedian(double[] array)
{
double median;
double middle = array.Length / 2;
Array.Sort(array);
if (array.Length % 2 == 0)
median = (double)(array[middle - 1] + array[middle]) / 2;
else
median = (double) array[middle];
return median;
}
}
The error is "Cannot implicit convert type double to int. Could be missing a cast." but I'm not certain that's the actual problem. It appears to be complaining about the middle
variable.