Friday, 20 November 2015

examples of plural selection switch statement:C Language

examples of plural selection switch statement:C Language
examples of plural selection switch statement:C Language
in today's post we will try statements plural switches that can count the number of letters that have been determined by the program.

#include <stdio.h>
#include <stdlib.h>

int main(){
    int value;
    int countA = 0; int countD = 0;
    int countB = 0; int countE = 0;
    int countC = 0; int countF = 0;
printf("the input value of the letters.\n");
printf("EOF character to end input,\n");
    while((value = getchar())!= EOF){
        switch(value){
    case'A':
    case'a':
    ++countA;
    break;

    case'B':
    case'b':
    ++countB;
    break;

    case'C':
    case'c':
    ++countC;
    break;

    case'D':
    case'd':
    ++countD;
    break;

    case'E':
    case'e':
    ++countE;
    break;

    case'F':
    case'f':
    ++countF;
    break;

    case'\n':
    case'\t':
    case' ':
    break;


    default:
        printf("the value entered incorrect\n");
        printf("input value of new letters.\n");
        break;
        }
    }
    printf("Total each letter :\n");
printf("A: %d\n",countA);
printf("B: %d\n",countB);
printf("C: %d\n",countC);
printf("D: %d\n",countD);
printf("E: %d\n",countE);
printf("F: %d\n",countF);
return 0;
}



 while((value = getchar())!= EOF){   
function "getchar" is derived from "<stdio.h>" that is useful to read characters from the keyboard and store it in the variable "int value".
EOF (end of file) is used to end like a "return 0;" with key "ctrl + z"


 switch(value){
    case'A':
    case'a':
    ++countA;
    break;
is used to determine which values to be entered. the program will run from top to bottom starting from "case 'A' case 'a'" to program "default :" under before closing curly brackets.

examples of plural selection switch statement:C Language

No comments:

Post a Comment