Skip to content

Instantly share code, notes, and snippets.

@Sander-Kastelein
Created January 20, 2016 11:30
Show Gist options
  • Save Sander-Kastelein/bd83b70aff9b8c6ed22e to your computer and use it in GitHub Desktop.
Save Sander-Kastelein/bd83b70aff9b8c6ed22e to your computer and use it in GitHub Desktop.
Voorbeeld
static void Main(string[] args)
{
Console.WriteLine(getWorstStudentName());
Console.ReadLine();
}
static string getWorstStudentName()
{
int maxStudentNr = 0;
foreach (Student student in students)
{
if (student.StudentNr > maxStudentNr) maxStudentNr = student.StudentNr;
}
int[] onvoldoendesPerStudentNr = new int[maxStudentNr];
foreach (Exam exam in exams)
{
if (exam.Score < 5.5m)
{
onvoldoendesPerStudentNr[exam.Student.StudentNr]++;
}
}
int maxOnvoldoendes = -1;
int studentNr = 0;
for (int i = 0; i < onvoldoendesPerStudentNr.Length; i++)
{
if (onvoldoendesPerStudentNr[i] > maxOnvoldoendes)
{
maxOnvoldoendes = onvoldoendesPerStudentNr[i];
studentNr = i;
}
}
foreach (Student student in students)
{
if (student.StudentNr == studentNr)
{
return student.Name;
}
}
foreach (Student student in students)
{
return student.Name;
}
throw new Exception("No students in students variable");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment