fig04_07.mod2.c (1074B)
1 /* Esercizio 4.30 (2) */ 2 3 #include <stdio.h> 4 5 int main() 6 { 7 int grade; 8 int aCount = 0, bCount = 0, cCount = 0, dCount = 0, fCount = 0; 9 10 printf("Enter the letter grades.\n"); 11 printf("Enter the EOF chatacter to end input.\n"); 12 13 while (( grade = getchar()) != EOF ) { 14 15 if (grade == 'A' || grade == 'a') { 16 ++aCount; 17 continue; 18 } 19 if (grade == 'B' || grade == 'b') { 20 ++bCount; 21 continue; 22 } 23 if (grade == 'C' || grade == 'c') { 24 ++cCount; 25 continue; 26 } 27 if (grade == 'D' || grade == 'd') { 28 ++dCount; 29 continue; 30 } 31 if (grade == 'F' || grade == 'f') { 32 ++fCount; 33 continue; 34 } 35 if (grade == '\n' || grade == '\t' || grade == ' ') 36 continue; 37 38 printf("Incorrect letter grade entered."); 39 printf("Enter a new grade.\n"); 40 41 } /* end of while */ 42 43 printf("Totals for each letter grade are:\n"); 44 printf("A: %d\n", aCount); 45 printf("B: %d\n", bCount); 46 printf("C: %d\n", cCount); 47 printf("D: %d\n", dCount); 48 printf("F: %d\n", fCount); 49 50 return 0; 51 } /* E0F main */ 52