Introduction
Control Statement
- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers
- Program to check leap year
- Program to find factorial of the number
- Program to find reverse of the number
Function
- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle
Array
Pointer
OOPS
No Examples found for this topic - CodeHelpPro
Program to check vowel or constant
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.";
else
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
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments