In this tutorial, we will write a C++ Program to Check Vowel or Consonant. To understand the example, you need to have knowledge of the following topic in C++.
There are total 26 alphabets together out of which 5 are the vowels (a, e, i, o, u) and the rest are the consonant.
The program below will take character input from the user to check. The program makes sure the vowel entered are the uppercase and lowercase letters then check using if..else statement.
Let us go through the program.
C++ Program to Check Whether a Character is Vowel or Consonant
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> using namespace std; int main() { char ch; cout << "Enter an alphabet: "; cin >> ch; if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') cout << ch << " is a Vowel"; else if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') cout << ch << " is a Vowel"; else cout << ch << " is a Consonant"; return 0; } |
Output:
//Run 1
Enter an alphabet: e
e is a Vowel
//Run 2
Enter an alphabet: j
j is a Consonant