You can't do it with that code: you need to store the inputs as they are entered so they can be accessed after the input is done. None of your inputs are available because they all go out of scope when the loop ends.
There are two ways to do this: I would create a Student class and write a method that collected the user input and returned a Student instance, then store them all in a collection such as a List - then getting the student with the highest grade is easy:
Student top = myStudents.Max(s => s.Grade);
. But it's also possible without a class if you keep an existing max and check within your loop:
Student top = new Student(null, 0.0, double.MinValue);
for (Int i = 0; i < 10; i++)
{
Student current = GetStudent();
if (current.Grade >= top.Grade)
{
top = current;
}
}
You can do this without a Student class, but it's more work and a lot messier.
By the way, you shouldn't use
double.Parse
with user inputs: users make mistakes, and your app will crash if they mistype. Getting to the tenth student and teh app crashing because you miskeyed is going to annoy users!
Instead, use
double.TryParse[
^] instead and report problems and let then re-do the input:
double grade;
while (true)
{
string inp = Console.ReadLine();
if (double.TryParse(inp, out grade))
{
break;
}
Console.WriteLine($"\"{inp}\" is not a number!");
}