C++ Program to check whether a Character is Vowel or Consonant using if–else.

 Write a program in CPP to check whether a character is vowel or consonant using if –else condition.

      The Program for checking a character to be a vowel or a consonant  is pretty easy. The given code is used in c++ (cpp) programming language. The compiler used for this code may be Dev-CPP or CodeBlocks. This code can also be used in Turbo CPP by making a little changes.
       The source code for Dev-CPP or CodeBlocks to check whether a character is vowel or consonant using if –else condition is:

Source Code:

Input:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char x;
cout<<"Enter the alphabet."<<endl;
cin>>x;
if(x=='a'||x=='e'||x=='i'||x=='o'||x=='u')
cout<<"The alphabet you entered is vowel";
else
cout<<"The alphabet you entered is consonant";
return 0;
}

Source Code for Turbo CPP:

#include<iostream.h>
#include<stdio.h>
void main()
{
char x;
cout<<"Enter the alphabet."<<endl;
cin>>x;
if(x=='a'||x=='e'||x=='i'||x=='o'||x=='u')
cout<<"The alphabet you entered is vowel";
else
cout<<"The alphabet you entered is consonant";
getche;
}

Output: 

output of cpp program to check a character to be vowel or consonant
output

Explanation:

                 What the program basically does is to check whether a character given by user is Vowel or Consonant. The program always starts from main body. A variable is declared by a character data type. It asks the user to Enter any alphabet. The user inputs the alphabet. The if condition checks the character for a, e, i, o, u. If the character matches one of them, it will print  "The alphabet you entered is vowel". Otherwise it will print "The alphabet you entered is consonant". Then the programs come to an end.



                Thank you for using our services. I hope this blog helped. To see more important and interesting posts like this please follow for blog. Thank you..!!!!!
             

Comments

Popular posts from this blog

How to do SEO for Blogger [Latest SEO tips]

How to Add Custom robots.txt to blog [LATEST CEO TRICK]

How to Add a Blog to Google Search Console [latest trick for SEO]