Please disable your adblock and script blockers to view this page
 

C++ Program to check for vowel or consonant using switch case

Introduction: In this article i am going to explain how to check whether entered character is vowel or consonant using switch-case statement in C++ Language. 

As we know there are 26 alphabets in English from which 5 are vowels, rest are consonants. The concept is very simple.  If entered character matches any of the small or capital letter 'a', 'e', 'i', 'o', 'u' ,'A', 'E', 'I', 'O', 'U' then it is vowel else consonant. In technical term if character matches any of the switch expression defined in the switch body in the form of cases the the control is transferred to that block otherwise to the default case.

Implementation: Let's create a program to check.

#include<conio.h>
#include<iostream.h>
main()
{
      char ch;
      cout<<"Enter any character from  A to Z := ";
      cin>>ch;
      switch(ch)
      {
      case 'A':
           cout<<"Vowel";
           break;
          
      case 'E':
           cout<<"Vowel";
           break;
     
      case 'I':
           cout<<"Vowel";
           break;
     
      case 'O':
           cout<<"Vowel";
           break;
     
      case 'U':
           cout<<"Vowel";
           break;
                
      case 'a':
           cout<<"Vowel";
           break;
          
      case 'e':
           cout<<"Vowel";
           break;
     
      case 'i':
           cout<<"Vowel";
           break;
     
      case 'o':
           cout<<"Vowel";
           break;
     
      case 'u':
           cout<<"Vowel";
           break;                                        
            
      default:
           cout<<"consonant";
      }     
      getch();             
      }

OUTPUT:

First Run:
Enter any character from  A to Z :=
u
Vowel

Second Run:
Enter any character from  A to Z :=
P
Consonant


Previous
Next Post »

2 comments

Click here for comments
Anonymous
admin
November 07, 2013 ×

can you detected my mistakes?..

int main (void)
{
char ch;
printf ("Enter ch "'a' && 'z' || 'A' && 'Z'", "'a'|| 'A'","'e' || 'E'","'o' || 'O'":= ");
scanf("ch");


switch(ch)
{

case "'a' && 'z' || 'A' && 'Z'" : printf ("NOT A LETTER") ;
break ;
case "'a'|| 'A'" : printf ("Vowel A") ;
break ;
case "'e' || 'E'" : printf ("Vowel E") ;
break ;
case "'o' || 'O'" : printf ("Vowel O") ;
break ;
default : printf ("NOT NOT A LETTER, Vowel A, Vowel E, Vowel O") ;
break ;
}
getch ();
return 0;
}

Reply
avatar
November 07, 2013 ×

Read the article:
Program to check for vowel or consonant using switch case in C Language
http://www.webcodeexpert.com/2013/07/program-to-check-for-vowel-or-consonant.html

Reply
avatar

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon