Question: /* Counting letter grades */ #include /* function main begins program execution */ int main() { char grade; /* one grade */ int aCount =
/* Counting letter grades */ #include
/* function main begins program execution */ int main() {
char grade; /* one grade */ int aCount = 0, bCount = 0, cCount = 0, dCount = 0; int fCount = 0;
printf( "Enter the letter grades. " ); printf( "Enter the EOF character to end input. " );
/* loop until user types end-of-file key sequence */ while ( ( grade = getchar() ) != EOF ) {
/* determine which grade was input */ switch ( grade ) { /* switch nested in while */
case 'A': /* grade was uppercase A */
case 'a': /* or lowercase a */ ++aCount; /* increment aCount */ break; /* necessary to exit switch */
case 'B': /* grade was uppercase B */
case 'b': /* or lowercase b */ ++bCount; /* increment bCount */ break; /* exit switch */
case 'C': /* grade was uppercase C */
case 'c': /* or lowercase c */ ++cCount; /* increment cCount */ break; /* exit switch */
case 'D': /* grade was uppercase D */
case 'd': /* or lowercase d */ ++dCount; /* increment dCount */ break; /* exit switch */
case 'F': /* grade was uppercase F */
case 'f': /* or lowercase f */ ++fCount; /* increment fCount */ break; /* exit switch */
case ' ': /* ignore newlines, */ case '\t': /* tabs, */ case ' ': /* and spaces in input */
break; /* exit switch */
default: /* catch all other characters */ printf( "Incorrect letter grade entered." ); printf( " Enter a new grade. " ); break; /* optional; will exit switch anyway */
} /* end switch */
} /* end while */
/* output summary of results */ printf( " Totals for each letter grade are: " ); printf( "A: %d ", aCount ); /* number of A grades */ printf( "B: %d ", bCount ); /* number of B grades */ printf( "C: %d ", cCount ); /* number of C grades */ printf( "D: %d ", dCount ); /* number of D grades */ printf( "F: %d ", fCount ); /* number of F grades */
return 0; /* indicate program ended successfully */
} /* end function main */

C language use same structure above code (switch) Assignment.7 *********************************** *********** ************************************ ************* Write a program to calculate the number of population in each province (Capital, Farwaniya, Hawaley, Jahra, *.(Mubarak_Alkabeer, Alahmadey C language use same structure above code (switch) Assignment.7 *********************************** *********** ************************************ ************* Write a program to calculate the number of population in each province (Capital, Farwaniya, Hawaley, Jahra, *.(Mubarak_Alkabeer, Alahmadey
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
