Skip to main content

Command Palette

Search for a command to run...

A Grade Calculator

A program which shows your grade when you enter your score.

Published
•1 min read•View as Markdown
#include <stdio.h>
/*
 * main - a function that prints the grade of students
 * grades - A=80 ... 100, B=70...79, C=60...69, D=50...59, E=40...49, F <40
 * the grades will be broken down sub-grading
 */
 int main(void)
 {
     int score;

     printf("Enter your score: \n");
     scanf("%d", &score); /* put your score here */

     if (score >= 80 && score <= 100)
        printf("Your grade is A.\n");
        if (score == 100)
            printf("Congratulation! You had a perfect score.\n");
        else if (score >= 90 && score < 100)
            printf("You had a Distinction.\n");
     else if (score >= 70 && score <= 79)
        printf("Your grade is B");

        /* breakdown of B+ and B- */
        if (score >= 75 && score <79)
            printf("+\n");
        else if (score >= 70 && score < 75)
            printf("-\n");
     else if (score >= 60 && score <= 69)
        printf("Your grade is C");

        /* breakdown for C+ and C- */
        if (score >= 65 && score <= 69 )
            printf("+\n");
        else if (score >= 60 && score < 65)
            printf("-\n");
     else if (score >= 50 && score <= 59)
        printf("Your grade is D");
     else if (score >= 40 && score <= 49)
        printf("Your grade is E");
     else if (score < 40)
        printf("Your grade is F");

    /* any other integer entered outside 0 ... 100 will show an error */
     else
        printf("Wrong input, try again.");

    return (0);
 }