#include <iostream>
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
std::cout << "Enter a letter in the alphabet (a - z): ";
std::cin >> c;
// evaluates to 1 (true) if c is a lowercase vowel
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 (true) if c is an uppercase vowel
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true
if (isLowercaseVowel || isUppercaseVowel)
std::cout << "'" << c << "' is a vowel.";
else
std::cout << "'" << c << "' is a consonant.";
return 0;
}
- Using an if...else statement to check whether an alphabet entered by the user is a vowel or a constant.
- Five alphabets a, e, i, o and u are known as vowels. All other alphabets except these 5 alphabets are known are consonants.
- This program assumes that the user will always enter an alphabet.
- - -
The `isLowerCaseVowel` evaluates to true if user input is a `lower case vowel` and false for any other character.
Similarly, isUpperCaseVowel evaluates to true if user input is a `upper case vowel` and false for any other character.
If both `isLowercaseVowel` and `isUppercaseVowel` is true, the character entered is a vowel , if not the character is a consonant.