OK, so I've been given an assignment due for Monday, which was to create a console program which allows the user to enter an unknown quantity of numbers, then have the Mean, Median and Mode averages displayed of said group of numbers.
So far I've managed to get the Mean and Median to work, for both odd and even quantities of variables. I am however stuck on getting it to calculate the modal average!

I don't really know how to approach this, would a structure with two fields, variable and quantity of variable, work?
Below is the code, I haven't made it display discrete of continuous data yet, I'm leaving that for the end.
Code:
Module Module1
Sub Main()
Start:
'Declare Variables
Dim dataType As String = "x"
Dim userInput As String = "x"
Dim data(0) As Double
Dim sum, mean, median, mode As Double
Dim count As UInt32 = 0
Dim n As UInt32 = 0
'Reset Values
sum = 0 : count = 0 : mean = 0 : median = 0 : mode = 0
'Set Title
Console.Title = "Statisticulator - By Sam Christy"
'Determine data type from user input
Do
Console.WriteLine("Is your Continuous (C) or Data Discrete (D)?")
dataType = Console.ReadLine()
If LCase(dataType) = "d" Then
dataType = "Discrete"
ElseIf LCase(dataType) = "c" Then
dataType = "Continuous"
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Invalid input: Please enter either 'C' or 'D'" & vbNewLine)
Console.ResetColor()
End If
Loop Until dataType = "Discrete" Or dataType = "Continuous"
Console.Clear()
Console.WriteLine("Data Type: {0}{1} ", dataType, vbNewLine)
'Allow user to input data and populate the array providing data is valid
Do
Console.Write("Number{0}: ", n + 1)
userInput = Console.ReadLine()
If userInput = "" Then
Exit Do
Else
ReDim Preserve data(n)
data(n) = userInput
n += 1
End If
Loop
'Calculate Sum of Variables
For Each number In data
sum += number
Next
Console.Clear()
'Sort the array of Variables in ascending order and set value of count
SortData(data)
count = data.Count
'Calculate Mean
CalculateMean(data.Count, sum, mean)
'Calculate Median
CalculateMedian(data, count, median)
'Calculate Mode
PrintData(data)
'Display Results
Console.WriteLine("")
Console.WriteLine("You entered {0} variables", count)
Console.WriteLine("Sum: {0}", sum)
Console.WriteLine("Mean: {0}", mean)
Console.WriteLine("Median: {0}", median)
Console.WriteLine("Mode: {0}", mode)
Console.WriteLine("")
Console.WriteLine("")
GoTo Start
End Sub
Sub CalculateMean(ByVal count As UInt32, ByVal sum As Double, ByRef mean As Double)
mean = sum / count
End Sub
Sub CalculateMedian(ByVal data As Array, ByVal count As UInt32, ByRef median As Double)
If count Mod 2 <> 0 Then
median = data(((count + 1) / 2) - 1)
Else
median = (data((count - 2) / 2) + data(count / 2)) / 2
End If
End Sub
Sub PrintData(ByVal data As Array)
For Each v In data
Console.WriteLine(v)
Next
End Sub
Sub SortData(ByRef ary As Array)
Dim Outer, Inner As Integer
Dim Temp As Double
For Outer = UBound(ary) To 0 Step -1
For Inner = 0 To Outer - 1
If ary(Inner) > ary(Inner + 1) Then
Temp = ary(Inner)
ary(Inner) = ary(Inner + 1)
ary(Inner + 1) = Temp
End If
Next
Next
End Sub
End Module