Switch statement with multiple case actions - C++ Statement

C++ examples for Statement:switch

Description

Switch statement with multiple case actions

Demo Code

#include <iostream>
#include <locale>

int main()//from  w  ww  .java2s  .  co m
{
  char letter {};
  std::cout << "Enter a letter: ";
  std::cin >> letter;

  if(isalpha(letter))
  {
    switch(tolower(letter))
    {
    case 'a': case 'e': case 'i': case 'o': case 'u':
      std::cout << "You entered a vowel." << std::endl;
      break;
    default:
      std::cout << "You entered a consonant." << std::endl;
      break;
    }
  }
  else
    std::cout << "You did not enter a letter." << std::endl;
}

Result


Related Tutorials