This line makes no sense and would not compile in "normal" language:
max = students(i).Average
First of all
is not assigned; second of all, you should not declare it, and finally, getting any element of the array for initial value of
won't make a correct algorithm. Instead do this:
max = double.NegativeInfinity
This special value will correctly compare using '<' operator (and other comparison operators) with any other double value except NaN and will serve as a correct initial value for maximum. Indeed, there won't be any number less then double.NegativeInfinity.
If you also need to use the
(or some other member of the
structure), you need to search not just for maximum, but also remember the index of the maximum element. If you think just a bit, you will easily modify the code the get it.