C++ program to check if a character is vowel or not

Introduction :

In this tutorial, we will learn how to find if a character is a vowel or not in C++. The program will ask the user to enter a character. It will then find out if the character is a vowel or not and print out the result to the user.

With this program, you will learn how if-else works in C++.

C++ program :

Below is the C++ program :

#include <iostream>
using namespace std;

int main()
{
    //1
    char c;

    //2
    cout << "Enter a character : ";
    cin >> c;

    //3
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
    {
        cout << "The entered character is a vowel\n";
    }
    else
    {
        cout << "The entered character is not vowel\n";
    }
}

Explanation :

The commented numbers in the above program denote the step numbers below :

  1. Create one character variable c to store the user input value.
  2. Ask the user to enter a character. Read the character using cin and store it in the variable c.
  3. We are using one if-else block to check if the entered character is vowel or not. The if block checks if the character is a vowel. It checks all lower case and upper case vowel characters using OR(||). If any of these conditions is true, it will enter the if block. Else, it will enter in the else block.

Sample Output :

Enter a character : a
The entered character is a vowel

Enter a character : X
The entered character is not vowel

Enter a character : U
The entered character is a vowel

c plus plus check character vowel

Conclusion :

In this tutorial, we have learned how to find a character is vowel or not. Try to go through the program and drop one comment below if you have any queries.