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

  • Write a program in C++ to check whether an alphabet is vowel or consonant.
  • How to check whether a character is consonant or vowel in C++.

To check whether a character is vowel or consonant, we will take a character as input from user using cin and store in char data type variable. Then, we check whether it is any one of these ten characters(lower and upper case vowels) a, A, e, E, i, I, o, O, u and U using || operator. If input character is any one of these ten vowel characters, then it is a vowel otherwise a consonant.

English has five proper vowel letters (A, E, I, O, U) all alphabets except these characters are consonants.

C++ Program to check whether an alphabet is vowel or Consonant

#include <iostream>

using namespace std;

int main() {
    char c;
    cout << "Enter a Character\n";
    cin >> c;
    /* Check if input alphabet is member of set{A,E,I,O,U,a,e,i,o,u} */
    if(c == 'a' || c == 'e' || c =='i' || c=='o' || c=='u' || c=='A'
          || c=='E' || c=='I' || c=='O' || c=='U'){
        cout << c << " is VOWEL";
    } else {
        cout << c <<" is CONSONANT";
    }
    
    return 0;
}
Output
Enter a Character
R
R is CONSONANT
Enter a Character
E
E is VOWEL