C++ switch statement read user choice

Description

C++ switch statement read user choice

#include <iostream>

int main()// ww  w .j a va2  s. c  om
{
  int choice {};             // Stores selection value

  std::cout << "You can choose from the following:\n"
            << "1 \n"
            << "2 \n"
            << "3 \n"
            << "4 \n\n"
            << "Enter your selection number: ";
  std::cin >> choice;

  switch(choice)
  {
  case 1:
    std::cout << "\n one." << std::endl;
    break;
  case 2:
    std::cout << "two." << std::endl;
    break;
  case 3:
    std::cout << "three." << std::endl;
    break;
  case 4:
    std::cout << "four." << std::endl;
      break;
  default:
    std::cout << "default." << std::endl;
  }
}



PreviousNext

Related