samedi 28 mai 2016

how to validate both lowercase and uppercase letters

Below I have written a program to evaluate a letter grade and print a message based on how well the score is. Let's say I wanted to get that information from the user input, how would i be able to accept both lower and upper case letters?

 #include <stdio.h>
 int main (){
/* local variable definition */
char grade = 'B';

if (grade == 'A'){ 
printf("Excellent!\n");
}
else if (grade == 'B' || grade == 'C'){
printf("Well done\n");
}
else if (grade == 'D'){
printf("You passed\n" );
}
else if (grade == 'F'){
printf("Better try again\n" );
}
else {
printf("Invalid grade\n" );
}
printf("Your grade is %c\n", grade );
return 0;
 }

Aucun commentaire:

Enregistrer un commentaire