This line makes no sense and would not compile in "normal" language:
max = students(i).Average
First of all
i
is not assigned; second of all, you should not declare it, and finally, getting any element of the array for initial value of
max
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
name
(or some other member of the
student
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. :-)
—SA