In this article, we will discuss the concept of the C++ program to Check Vowel or consonant using switch case statements
In this post, we are going to learn how to check the vowels and consonants using switch statements in the C++ programming language
The program allows to enter an Alphabet and it checks and displays whether the given alphabet is vowel or consonant with the break statements
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { char ch; cout<<"Enter any Alpabet\n"; //input alphabet from user cin>>ch;//store the Entered Alphabet in ch switch(ch){ //check lower case vowel letters case 'a': cout<<ch<<" is a vowel"; break; case 'e': cout<<ch<<" is a vowel"; break; case 'i': cout<<ch<<" is a vowel"; break; case 'o': cout<<ch<<" is a vowel"; break; case 'u': cout<<ch<<" is a vowel"; break; //check upper case vowel letters case 'A': cout<<ch<<" is a vowel"; break; case 'E': cout<<ch<<" is a vowel"; break; case 'I': cout<<ch<<" is a vowel"; break; case 'O': cout<<ch<<" is a vowel"; break; case 'U': cout<<ch<<" is a vowel"; break; default: cout<<ch<<" is a consonant"; break; } getch(); return 0; }
When the above code is executed, it produces the following result
case 1
Enter any Alphabet u u is a vowel
case 2
Enter any Alphabet I I is a vowel
case 3
Enter any Alphabet N N is a consonant
case 4
Enter any Alphabet d d is a consonant
Approach
The program allows to enter an Alphabet and it checks and displays whether the given alphabet vowel or consonant without the break statements
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { char ch; cout<<"Enter any Alpabet\n"; //input alphabet from user cin>>ch;//store the Entered Alphabet in ch switch(ch){ //check lower case vowel letters case 'a': case 'e': case 'i': case 'o': case 'u': //check upper case vowel letters case 'A': case 'E': case 'I': case 'O': case 'U': cout<<ch<<" is a vowel"; break; default: cout<<ch<<" is a consonant"; break; } getch(); return 0; }
When the above code is executed, it produces the following result
case 1
Enter any Alphabet i i is a vowel
case 2
Enter any Alphabet U U is a vowel
case 3
Enter any Alphabet H H is a consonant
case 4
Enter any Alphabet b b is a consonant
Approach
Suggested for you
Switch case statements in C++ language
Similar post
Java program to check Vowel or consonant using switch case statements
C program to check Vowel or consonant using switch case statements
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…