Find Vowels using Switch Case in C++


This C++ program takes an input of an alphabet and uses a switch statement to check whether the entered alphabet is a vowel or not. Here's how the program works:

  • The program prompts the user to enter an alphabet.
  • The user enters a single alphabet in lower case.
  • The program uses a switch statement to check which alphabet was entered.
  • If the entered alphabet is one of 'a', 'e', 'i', 'o', or 'u', the program outputs that it is a vowel alphabet.
  • If the entered alphabet is not one of these, the program outputs that it is not a vowel.
  • The break statement is used to end each case statement and prevent the program from executing subsequent case statements.
  • Finally, the program returns 0 to indicate successful execution.

Overall, this program is a good example of how to use a switch statement in C++ to handle multiple cases. However, it could be improved by adding input validation to check that the entered input is a valid lower case alphabet. Additionally, it could be modified to handle upper case alphabets as well by converting the entered alphabet to lower case before checking for vowel status.

Source Code

#include<iostream>
using namespace std;
int main()
{
    char x;
    cout<<"\nEnter the alphabet :";
    cin>>x;
        switch(x)
        {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                cout<<"\n"<<x<<" is a vowel alphabet";
                break;
            default:
                cout<<"\n"<<x<<"\n is not a vowel";
                break;
        }
    return 0;
}
To download raw file Click Here

Output

Enter the alphabet :e
e is a vowel alphabet

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples