C++ Switch statement with multiple case actions

Description

C++ Switch statement with multiple case actions

#include <iostream>
#include <locale>

int main()/*from   w  w w.ja va  2s .  c om*/
{
  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;
}



PreviousNext

Related