/* 


   Fig. 4.7: fig04_07.c
   Counting letter grades 
*/

#include <stdio.h>

int main(void) {

   int grade;
   int aCount = 0, bCount = 0, cCount = 0, dCount = 0, fCount = 0;

   printf(  "Enter the letter grades.\n"  );
   printf(  "Enter the EOF character to end input.\n"  );
   printf(  "EOF is Ctrl+Z Win, Ctrl+d(enter) Unix.\n");

   while ( ( grade = getchar() ) != EOF ) { /* EOF is Ctrl+Z Win, Ctrl+d(enter) Unix */

      switch ( grade ) {    /* switch nested in while */

        case 'A':   	/* grade was uppercase A */
        case 'a': 	/* or lowercase a */
		++aCount;         
	 	break;

        case 'B': 	/* grade was uppercase B */
	case 'b':  	/* or lowercase b */
            	++bCount;         
            	break;

        case 'C': 	/* grade was uppercase C */
	case 'c':  	/* or lowercase c */
            	++cCount;         
            	break;

        case 'D': 	/* grade was uppercase D */
	case 'd':  	/* or lowercase d */
		++dCount;
		break;

	case 'F': 	/* grade was uppercase F */
	case 'f':  	/* or lowercase f */
		++fCount;         
		break;

        case '\n': 	/* ignore carriage return */
	case ' ':   	/* ignore space */
		break;

         default:	/* catch all other characters */
		printf( "Incorrect letter grade entered. Enter a new grade.\n" ); 
		break;

      } /* end switch */

   } /* end while */

   printf( "\nTotals for each letter grade are:\n" );
   printf( "A: %d\n", aCount );
   printf( "B: %d\n", bCount );
   printf( "C: %d\n", cCount );
   printf( "D: %d\n", dCount );
   printf( "F: %d\n", fCount );

   return 0;

}

/* example interaction

		Enter the letter grades.
		Enter the EOF character to end input.
		EOF is Ctrl+Z Win, Ctrl+d(enter) Unix.
		a
		A
		G
		Incorrect letter grade entered. Enter a new grade.
		D
		F
		c
		C
		b
		b
		B
		Totals for each letter grade are:
		A: 2
		B: 3
		C: 2
		D: 1
		F: 1

		*/

/**************************************************************************
 * (C) Copyright 2000 by Deitel & Associates, Inc. and Prentice Hall.     *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/