Codeforcoding

C++ program to Check Vowel or consonant using switch case

C++ program to Check Vowel or consonant using switch case

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

C++ program to Check Vowel or consonant using switch case
Check vowel and consonants

Check Vowel or consonant using switch case statements with the break

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

 


Check Vowel or consonant using switch case statements without the break

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

Data type in C++ language

Variable in C++ language

The operator in C++ language

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

Java program to check Vowel or consonant using switch case statements
C program to check Vowel or consonant using switch case
Exit mobile version