This is a C++ Program to Check if a Character is a Vowel, Consonant or Digit.
The program takes a character and checks if it is a vowel, consonant or a digit.
1. A character is entered.
2. Using nested if else condition, the character is checked if it is a vowel, consonant or a digit.
3. The result is printed.
4. Exit.
Here is the source code of C++ Program to Check if a Character is a Vowel, Consonant or Digit. The program output is shown below.
#include<iostream>
#include<ctype.h>
using namespace std;
int main ()
{
char ch;
cout << "Enter a character : ";
cin >> ch;
if (isdigit(ch))
cout << "\nThe entered character is a digit.";
else if (isalpha(ch))
{
if ((ch == 'A') || (ch == 'E')|| (ch == 'I')|| (ch == 'O')|| (ch == 'U')|| (ch == 'a')|| (ch == 'e')||
(ch == 'i')|| (ch == 'o')|| (ch == 'u'))
cout << "\nThe entered character is a vowel.";
else
cout << "\nThe entered character is a consonant.";
}
else
cout << "\nThe entered character is a special character.";
return 0;
}
1. The user is asked to enter a character and is stored in the variable ‘char’.
2. The character is checked if it is a vowel, consonant or digit using functions under the library ctype.h.
3. If it is neither of the three, then the entered character is a special character,
4. The result is then printed.
Case 1 : Enter a character : I The entered character is a vowel. Case 2 : Enter a character : / The entered character is a special character. Case 3 : Enter a character : 8 The entered character is a digit.
Sanfoundry Global Education & Learning Series – C++ Programs.
To practice all C++ programs, here is complete set of 1000+ C++ Programming examples.
- Practice Programming MCQs
- Check Programming Books
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Check Computer Science Books