Press "Enter" to skip to content

Check Whether the Given Character is a Vowel or Consonant in C++

‘Check whether a given character is a vowel or consonant’ is a common question in programming basics. The answer and the logic of the program is simple.

We know that the letters A, E, I, O and U are considered as vowels and rest of them are named as consonants.

In programming, if the given character is one of the letters from vowels, then program prints as ‘vowel’, else the letter should be a consonant.

You can do the program using switch case and if-else statements.

Using Switch case

Here the entered characters is checked with a switch case. The default part means the rest of letters, that is consonants.

#include <iostream>
using namespace std;

int main()
{
    char c;
    cout << "Type a character :";
    cin>>c;
    switch(c)
    {
      case 'A':
      case 'E':
      case 'I':
      case 'O':
      case 'U':
          cout<<"Vowel";
          break;
      default :
          cout<<"Not a Vowel";
    }
    return 0;
}

Considering both Capital and Small letters

Above program considers only capital letters. if you want to check both small and capital vowel letters, then you need to add all the letters into the switch case.

#include <iostream>
using namespace std;

int main()
{
    char c;
    cout << "Type a character :";
    cin>>c;
    switch(c)
    {
      case 'A':
      case 'a':
      case 'E':
      case 'e':
      case 'I':
      case 'i':
      case 'O':
      case 'o':
      case 'U':
      case 'u':
          cout<<"Vowel";
          break;
      default :
          cout<<"Not a Vowel";
    }
    return 0;
}

Using  if – else statement

The ‘if statement’ checks the given character is from vowel letters, if yes, then should be vowel, else it should be a consonant.

#include <iostream>
using namespace std;

int main()
{
    char c;
    cout << "Type a character :";
    cin>>c;
    if(c == 'A' || c == 'E'|| c == 'I'|| c == 'O'|| c == 'U')
    {
      cout<<"Vowel";
    }
    else
    {
      cout<<"Not a Vowel";
    }

    return 0;
}

You can also add both small and capital letters like as we shown in switch case.

Sample Output:

Check Whether the Given Character is a Vowel or Consonant in C++

One Comment

  1. zortilonrel zortilonrel 22nd May 2021

    Very good written story. It will be useful to everyone who utilizes it, including me. Keep up the good work – can’r wait to read more posts.

Leave a Reply