Write a  C++ Program to Check Whether a character is Vowel or Consonant

C++ Program to Check Whether a character is Vowel or Consonant

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Check Whether a character is Vowel or Consonant
C++ Program to Check Whether a character is Vowel or Consonant

Write a  C++ Program to Check Whether a character is Vowel or Consonant

1. PROGRAM: C++ Program to Check Whether a character is Vowel or Consonant

/* C++ Program to Check Whether a character is Vowel or Consonant */

#include <iostream>
using namespace std;

int main() {
char c;
bool isLowercaseVowel, isUppercaseVowel;

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

// evaluates to 1 (true) if c is a lowercase vowel
isLowercaseVowel = (c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’);

// evaluates to 1 (true) if c is an uppercase vowel
isUppercaseVowel = (c == ‘A’ || c == ‘E’ || c == ‘I’ || c == ‘O’ || c == ‘U’);

// show error message if c is not an alphabet
if (!isalpha(c))
printf(“Error! Non-alphabetic character.”);
else if (isLowercaseVowel || isUppercaseVowel)
cout << c << ” is a vowel.”;
else
cout << c << ” is a consonant.”;

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *