luc043.c (1748B)
1 /* Write a program to find the grace marks for a student using switch. 2 The user should enter the class obtained by the student and the 3 number of subjects he has failed in. Use the following logic. 4 - If the student gets first class and he fails in more than 3 5 subjects, he does not get any grace, Otherwise, he gets a grace 6 of 5 marks per subject. 7 - If the student gets second class and he fails in more than 2 8 subjects, he does not get any grace. Otherwise, he gets a grace 9 of 4 marks per subject. 10 - If the student gets third class and he fails in more than 1 11 subject, then he does not get any grace. Otherwise, he gets a 12 grace of 5 marks. 13 */ 14 /* Let Us C, Chap- 7, Page - 125, Qn No.: C */ 15 16 #include <stdio.h> 17 18 int main() 19 { 20 int studentClass, failedSubjectCount, graceMarks = 0; 21 printf("Class obtained by the student (Enter 1 for First Class, 2 for Second Class, 3 for Third Class): "); 22 scanf("%d", &studentClass); 23 printf("Failed Subject Count: "); 24 scanf("%d", &failedSubjectCount); 25 26 if (failedSubjectCount < 0) { 27 printf("\nFailed subject count cannot be negative."); 28 return 1; 29 } 30 31 switch (studentClass) 32 { 33 case 1: 34 if (failedSubjectCount <= 3) 35 { 36 graceMarks += 5 * failedSubjectCount; 37 } 38 break; 39 40 case 2: 41 if (failedSubjectCount <= 2) 42 { 43 graceMarks += 4 * failedSubjectCount; 44 } 45 break; 46 47 case 3: 48 if (failedSubjectCount <= 1) 49 { 50 graceMarks += 5 * failedSubjectCount; 51 } 52 break; 53 54 default: 55 printf("\nWrong Choice."); 56 return 1; 57 } 58 59 printf("\nStudent will get %d grace marks.", graceMarks); 60 return 0; 61 }