Vowel/Consonant Check
Program to check if a character is a vowel or consonant
BeginnerTopic: Conditional Programs
C++ Vowel/Consonant Check Program
This program helps you to learn the fundamental structure and syntax of C++ programming.
#include <iostream>
#include <cctype>
using namespace std;
int main() {
char ch;
cout << "Enter a character: ";
cin >> ch;
// Convert to lowercase for easier checking
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
cout << "Vowel" << endl;
} else if (ch >= 'a' && ch <= 'z') {
cout << "Consonant" << endl;
} else {
cout << "Not an alphabet" << endl;
}
return 0;
}Output
Enter a character: E Vowel
Understanding Vowel/Consonant Check
This program checks if a character is a vowel or consonant. We use tolower() to convert the character to lowercase for case-insensitive checking. We check if the character is one of the five vowels (a, e, i, o, u). If not, and it's an alphabet, it's a consonant.
Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.