Created
January 20, 2016 11:30
-
-
Save Sander-Kastelein/bd83b70aff9b8c6ed22e to your computer and use it in GitHub Desktop.
Voorbeeld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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