Write a program to find grace marks for a student using switch. The user should enter the class obtained by student and the number of subjects he has failed in uses the follow logic.
 if the student gets first class and the number of subjects he failed in is greater than 3 then he does not get any 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 subject.

Recommended Answers

All 3 Replies

Write a program to find grace marks for a student using switch. The user should enter the class obtained by student and the number of subjects he has failed in uses the follow logic.
 if the student gets first class and the number of subjects he failed in is greater than 3 then he does not get any 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 subject.

Try to do this yourself, and post code with specific questions if you have a problem.

#include<stdio.h>
#include<conio.h>
void main()
{

    int class, nos_fail, grace;
    printf("Enter class obtained by student and number of subjects he failed in ");
    scanf("%d%d",&class,&nos_fail);
    switch(class)
    {
        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();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.