C++ Program to Check Whether a Character is Vowel or Consonant.

In this basic C++ program, we will have a look at how to check whether a character is a vowel or consonant. Vowels are the alphabets a, e, i, o, u.

C++ Program to Check Whether a Character is Vowel or Consonant.

Here is the source code of the C++ program to check if a character is Vowel, Consonant or Digit.

#include<iostream>
#include<ctype.h>
using namespace std;
int main ()
{
    char ch;
    cout << "Please enter a character : ";
    cin >> ch;
    if (isdigit(ch))
        cout << "\nIt is a digit.";
    else if (isalpha(ch))
        {
            if ((ch == 'A') || (ch == 'E')|| (ch == 'I')|| (ch == 'O')|| (ch == 'U')|| (ch == 'a')|| (ch == 'e')|| 
            (ch == 'i')|| (ch == 'o')|| (ch == 'u'))
                cout << "\nThe entered character is a vowel.";
            else
                cout << "\nIt is a consonant.";
        }
        else 
            cout << "\nIt is a special character.";
    return 0;
}

Output

Please enter a character : e
It is a vowel.

Leave a Comment

Your email address will not be published. Required fields are marked *