Write a C++ Program to check vowel or a consonant manually in a given string.

Program Code:


#include <iostream>
using namespace std;
int main()
{
char ch;  
int uv, lv;
cout << "Enter your alphabet : "; 
cin >> ch;
// evaluate true if c is a lowercase vowel 
lv = (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
// evaluates true if c is an uppercase vowel
uv = (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U');
// evaluates to true if either ilv or uv is true
if (lv || uv) 
{
cout << ch << " is a vowel.";
}
else   
{  
cout << ch << " is a consonant.";   
}
return 0;
}

The program output is tested on www.jdoodle.com



Output:
Enter your alphabet : g
is a consonant.

Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: