Skip to content

Commit

Permalink
add check for student in multiple grades
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf99 committed Feb 28, 2021
1 parent 9bca3c7 commit 00258b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions exercises/practice/grade-school/.meta/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ static int compare_student_grades_and_names(const void *s1, const void *s2)
return compare_student_names(student1, student2);
}

static bool are_students_in_multiple_grades(roster_t students)
{
for (size_t i = 0; i < students.count; ++i)
for (size_t j = 0; j < students.count; ++j)
if (i != j
&& !strncmp(students.students[i].name, students.students[j].name,
MAX_NAME_LENGTH)
&& students.students[i].grade != students.students[j].grade)
return true;

return false;
}

bool add_student(char *name, uint8_t grade)
{
bool added = false;
Expand All @@ -49,6 +62,9 @@ roster_t get_grade(uint8_t grade)
{
roster_t grade_roster = { 0 };

if (are_students_in_multiple_grades(roster))
return grade_roster;

for (size_t i = 0; i < roster.count && grade_roster.count < MAX_STUDENTS;
++i) {
if (roster.students[i].grade == grade) {
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/grade-school/test_grade_school.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void test_a_student_cant_be_in_two_different_grades(void)
(student_t) {1, "Aimee"},
(student_t) {2, "Aimee"}}
};
uint8_t desired_grade = 5;
uint8_t desired_grade = 2;

populate_roster(&input);

Expand Down

0 comments on commit 00258b5

Please sign in to comment.