A Program to Check Whether a Character is Vowel or Consonant
In this example, we are giving a program which is useful to check whether a character given by the user is vowel or consonant.
Program to check Vowel or Consonant:
#include <iostream>
using namespace std;
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
cout << "Enter an alphabet: ";
cin >> c;
// true if c is a lowercase vowel
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// true if c is an uppercase vowel
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// true if either isLowercaseVowel or isUppercaseVowel is true
if (isLowercaseVowel || isUppercaseVowel)
cout << c << " is a vowel.";
else
cout<< c << " is a consonant.";
return 0;
}
Output:
Enter an alphabet: E E is a vowel.