This question already has an answer here:
- abnormal behavior of scanf 3 answers
#include <stdio.h>
int main() {
printf("The mimimum attendance for giving the examination is 75 percent. \n");
printf("enter details to check eligibility:\n");
float a, b;
printf("enter the total no. of classes held.\n");
scanf("%d", &a);
printf("enter the no. of classes attended.\n");
scanf("%d", &b);
if((b/a) * 100 < 75) {
printf("your attendance is less than 75%.\n");
char c;
printf("Do you have a medical cause? 'Y' for yes and 'N' for no.\n");
scanf("%ch", &c);
switch(c) {
case 'Y':
printf("you are eligible for giving the examinations.");
break;
case 'N':
printf("sorry, you are not eligible for giving the examinations.");
break;
default:
printf("Invalid input.");
}
} else {
printf("you are eligible for giving the examinations.");
}
return 0;
}
here, when the first "if" statement runs, it asks for an input which is expected. But when the user gives an input of 'Y' or 'N', which are, the first and second case statements respectively, the compiler prints"invalid input", which is the default statement.
Aucun commentaire:
Enregistrer un commentaire