Write a program that asks the user to enter the character from a-z.

Write a program that asks the user to enter the character from a-z. The program will then display the user that the character entered is vowel or consonant. Solve the problem using the switch statements

code :
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "Enter any character";
cin >> ch;
if (isalpha(ch))
{
switch (ch)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case'u':
cout << "You entered a vowel";
break;
default:
cout << "You entered a consonant";
 
break;
}

}
}

output :
Enter any character       a
a
You entered a vowel

Post a Comment

0 Comments