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.
Description: In previous articles i explained the program for Else if ladder or multiple else if to check character is vowel or consonant in C++ language and How to find month name corresponding to number using switch case and How to find week day corresponding to number using switch case.
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.
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
2 comments
Click here for commentscan you detected my mistakes?..
Replyint 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;
}
Read the article:
ReplyProgram 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
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..