Easy Tutorial
❮ Unary Operators Overloading Cpp Examples Cout Cin ❯

C++ Example - Identifying Vowels/Consonants

C++ Examples

English has 26 letters, with vowels consisting only of the five letters a, e, i, o, and u; all others are consonants. The letter y is considered a semi-vowel and semi-consonant, but in English, it is generally treated as a consonant.

Example

#include<iostream> 
using namespace std; 

int main() { 
    char c;
    bool ischar; 
    int isLowercaseVowel, isUppercaseVowel;
    cout << "Enter a letter: "; 
    cin >> c; 
    ischar = ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
    if (ischar) {
        // Lowercase vowel
        isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); 
        // Uppercase vowel
        isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
        // if statement to check
        if (isLowercaseVowel || isUppercaseVowel)
            cout << c << " is a vowel"; 
        else 
            cout << c << " is a consonant"; 
    } else {
        cout << "The input is not a letter."; 
    }

    return 0; 
}

The above program outputs the following result:

Enter a letter: G
G is a consonant

C++ Examples

❮ Unary Operators Overloading Cpp Examples Cout Cin ❯