training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

fig04_07.mod.c (1003B)


      1 /* Esercizio 4.30 (1) */
      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       else if (grade == 'B' || grade == 'b')
     18 	 ++bCount;
     19       else if (grade == 'C' || grade == 'c')
     20 	 ++cCount;
     21       else if (grade == 'D' || grade == 'd')
     22 	 ++dCount;
     23       else if (grade == 'F' || grade == 'f')
     24 	 ++fCount;
     25       else if (grade == '\n' || grade == '\t' || grade == ' ') ; /* nothing */
     26       else {
     27          printf("Incorrect letter grade entered.");
     28 	 printf("Enter a new grade.\n");
     29       }
     30    } /* end of while */
     31 
     32    printf("Totals for each letter grade are:\n");
     33    printf("A: %d\n", aCount);
     34    printf("B: %d\n", bCount);
     35    printf("C: %d\n", cCount);
     36    printf("D: %d\n", dCount);
     37    printf("F: %d\n", fCount);
     38 
     39    return 0;
     40 } /* E0F main */
     41