logo image

C++ program take a character and tell its vowel or consonant

28


Following program shows you how to take a character and tells its vowel or consonant. In this program we get a character from user and shows it's vowel or consonant using if condition

#include <iostream>
#include <string>

int main() {
	char input;
	std::cout << "Please enter a character:";
	std::cin >> input;
	if (input == 'a' || input == 'A' || input == 'e' || input == 'E' ||
		input == 'i' || input == 'I' || input == 'o' || input == 'O' ||
		input == 'u' || input == 'U') {
		std::cout << "Its a vowel";
	} else if (
		(input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z')) {
		std::cout << "Its a consonant";
	} else {
		std::cout << "Its not an alphabet";
	}
}

Output:

Example1:

Please enter a character: e
Its a vowel 

Example2:

Please enter a character: x
Its a consonant 

Example3:

Please enter a character: 3
Its not an alphabet