Page Rank Checker

Monday 7 July 2014

Find Grace Marks Of Student Using Switch Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program which to find the grace marks for a student using switch. The use should enter the class obtained by the student and the number of subjects he has failed in. Use the following logic:
    - If the student gets first class and the number of students he failed in is greater than 3, then he does not get ay grace. If the number of subjects he failed in is less than or equal to 3, then the grace is of 5 marks per subject.
    - If the student gets second class and the number of subjects he failed in is greater than 2, then he does not get any grace. If the number of subjects he failed in is less than or equal to 2, then the grace is of 4 marks per subject.
    - If the student gets third class and the number of subjects he failed in is greater than 1, then he does not get any grace. If the number of subjects he failed in is equal to 1, then the grace is of 5 marks per sunject.

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int clss, nos_fail, grace;
    printf("Enter class obtained by student and number of subjects he failed in ");
    scanf("%d%d",&clss,&nos_fail);
    switch(clss)
    {
        case 1:
            switch(nos_fail)
            {
                case 1:
                case 2:
                case 3:
                    grace=5;
                    break;

                default:
                    grace=0;
                    break;
            }
            break;

        case 2:
            switch(nos_fail)
            {
                case 1:
                case 2:
                    grace=4;
                    break;

                default:
                    grace=0;
                    break;
            }
            break;

        case 3:
            switch(nos_fail)
            {
                case 1:
                    grace=5;
                    break;

                default:
                    grace=0;
                    break;
            }
            break;
    }
    printf("\nStudent will get %d grace marks per subject",grace);
    getch();
}