LearnFrenzy
Sign in Take a free test

Decision Making · Decision Making Programs · Question 3

Result with marks and attendance rules in C Solution, output & explanation

  • Program
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

Decide each student's result: distinction (marks ≥ 75 and attendance ≥ 75), pass (marks ≥ 40 and attendance ≥ 75), detained (marks ≥ 40 but low attendance), otherwise fail.

Solution
main.c
#include <stdio.h>

const char *result(int marks, int attendance) {
    if (marks < 40)
        return "fail";
    if (attendance < 75)
        return "detained";
    return marks >= 75 ? "distinction" : "pass";
}

int main(void) {
    int s[][2] = {{82, 90}, {55, 80}, {65, 60}, {30, 95}};
    for (int i = 0; i < 4; i++)
        printf("%d%%, %d%% -> %s\n", s[i][0], s[i][1], result(s[i][0], s[i][1]));
    return 0;
}

Output Verified by compiling and running

82%, 90% -> distinction
55%, 80% -> pass
65%, 60% -> detained
30%, 95% -> fail

Guard clauses remove the failing cases one at a time, so the final line only distinguishes distinction from pass. Every combination of the two rules is covered exactly once.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links