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:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. char c;
  6. int isLowercaseVowel, isUppercaseVowel;
  7. cout << "Enter an alphabet: ";
  8. cin >> c;
  9. // true if c is a lowercase vowel
  10. isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
  11. // true if c is an uppercase vowel
  12. isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
  13. // true if either isLowercaseVowel or isUppercaseVowel is true
  14. if (isLowercaseVowel || isUppercaseVowel)
  15. cout << c << " is a vowel.";
  16. else
  17. cout<< c << " is a consonant.";
  18. return 0;
  19. }

Output:

Enter an alphabet: E
E is a vowel.