Menu Close

C++ Program To Check a Character Vowel or Consonant

C++ Program To Check a Character Vowel or Consonant

In this C++ example, we are going to write a C++ Program To Check a Character Vowel or Consonant.
To check a vowel character and consonant character, we will use C++ if..else statement. In this example we will ask a character from the user, then we will check a character vowel or consonant using C++.

In previous tutorial we have seen How to check a number is odd or even.

Before going through this tutorial, Let’s understand what is vowel and consonants ?

What is vowels?

Vowels refers to the a, e, i, o, u characters.

What is Consonants?

Consonants refers to the rest of character except vowel’s characters.

Example: C++ Program To Check a Character Vowel or Consonant

#include<iostream>
using namespace std;

int main()
{

char c;
int lowercharacter, uppercharacter;

cout<<"Enter you character to check vowel or not:- ";
cin>>c;

lowercharacter = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
uppercharacter = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

if ( lowercharacter || uppercharacter )
{
	cout<<c<<" is vowel";	
}

else 
{
	cout<<c<<" is consonant";
}

return 0;

}

Output:

Enter you character to check vowel or not:- a                                                                                 
a is vowel  

Enter you character to check vowel or not:- A                                                                                 
A is vowel 

Enter you character to check vowel or not:- s                                                                                   
s is consonant 

Explain The Above Code:

  • The lowercharacter return true if the entered character by the user is the lower case otherwise return false.
  • The uppercharacter return true if the entered character by the user is the upper case otherwise return false.
  • If both lowercharacter and uppercharacter are true, The entered character is vowel otherwise entered character is consonant.

Conclusion:

In this tutorial, you have learned how to write a C++ Program To Check a Character Vowel or Consonant.
In this article, we have used C++ if..else statement to check a character vowel or consonant using C++.

I hope this article will help you. If you like this article, please share with your friends who want to learn C++ and write this type of C++ program.

For More Information:- Click Here

C++ Program to Check Number Even or Odd ( 2 Best Ways )

Related Posts