Write a C++ Program to check vowel or a consonant manually in a given string.
Program Code:
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
g is a consonant.
Thanks
Mukesh Rajput
Post A Comment:
0 comments: