Program to check vowel or constant

0 Suresh Chand March 28, 2021

In this example, We will learn how to check whether a character is vowel or constant using C++ programming language.

To do this, first we check whether input is alphabet or not. If it is alphabet then, We will equivalate with five vowel letters (a, e, i, o, u).

Let’s look an example to make clear concepts

#include <iostream>
using namespace std;

int main() {
    char c;
    int isLowerCaseVowelCharacter, isUpperCaseVowelCharacter;

    cout << "Enter an alphabet: ";
    cin >> c;

    // return 1 (true) if c is a lowercase vowel
    isLowerCaseVowelCharacter = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

    // return 1 (true) if c is an uppercase vowel
    isUpperCaseVowelCharacter = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

    // if c is not an alphabet then show error message
    if ( ! isalpha ( c ) )
      printf("Error! Non-alphabetic character.");
    else if (isLowerCaseVowelCharacter || isUpperCaseVowelCharacter)
        cout << c << " is a vowel.";
        cout << c << " is a consonant.";

    return 0;

The output of above program is

Enter an alphabet: a
a is a vowel

Enter an alphabet: c
c is a constant

Notify of
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.



Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System