Q:

Using an if statement to determine the highest value

My code asks the user to enter a certain amount of students and to enter there name and score depends on how many students there are. My question is, how would I use an if statement to find out the student with the highest score. (C#)
class Class1
{

    public void studentCount()
    {
        int studentcount;
        int i;
        int x;
        string studentname = "";

        Console.WriteLine("Enter how many students there are: ");
        studentcount = Convert.ToInt32(Console.ReadLine());
        {
            for (i = 1; i <= studentcount; i++)
            {
                Console.WriteLine("Enter students name: ");
                studentname = Convert.ToString(Console.ReadLine());
                Console.WriteLine("Enter students score: ");
                x = Convert.ToInt32(Console.ReadLine());
            }
        }

A:

Keep track of the current highest x (student's score) and if a new one that's entered is higher than the last highest, update the last highest score's variable and that student's name. You'll need to use one more variable for this to keep track of the current max score. You can always update the student's name to match the student with the max score. After the loop, you can output that student's score and name.

A:

Respecting your actual code, probably this would suit you well.
int studentcount = 0, i = 0, x = 0, highestScore = 0;
string studentname = "", highestScoreStudentName = "";

Console.WriteLine("Enter how many students there are: ");

studentcount = Convert.ToInt32(Console.ReadLine());
{
    for (i = 1; i <= studentcount; i++)
    {
        Console.WriteLine("Enter students name: ");
        studentname = Convert.ToString(Console.ReadLine());
        Console.WriteLine("Enter students score: ");
        x = Convert.ToInt32(Console.ReadLine());

        if (x > highestScore)
        {
            highestScore = x;
            highestScoreStudentName = studentname;
        }
    }
}

