Chapter - 5: The Case Control Structure

Write a program which to find the grace marks for a student using switch. The user should enter the class obtained by the student and the number of subjects he has failed in.


D
Sections
1
Exercises

- 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


#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b;
    printf("\nEnter your class : ");
    scanf("%d", &a);
    printf(" \nEnter your number of subjects in which you are failed : ");
    scanf("%d", &b);
    switch(a)
    {
    case(1):
        switch(b)
        {
        case(3):
        case(2):
        case(1):
        case(0):
            printf("You've got the grace of 5 marks.");
            break;			
        default:
            printf("You will not get any grace.");
        }
        break;
            
    case(2):
        switch(b)
        {
        case(2):
        case(1):
        case(0):
            printf("You've got the grace of 4 marks.");
            break;				
        default:
            printf("You will not get an grace.");
            break;
        }
        break;
        
    case(3):
        switch(b)
        {
        case(1):
        case(0):
            printf("You've got the grace of 5 marks.");
            break;
        default:
            printf("You will not get any grace.");
            break;
        }
        break;
            
    default:
        printf("\n\nWrong choice of class.\nTry again!!");
        break;	
    }
    getch();
    return 0;
}

© 2021 Garbage Valuegarbage value logo