avr39ripe

BR012enumExample

Jan 27th, 2021
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     enum Directions {North,South,East,West};
  6.  
  7. /*
  8.     const int North{ 0 };
  9.     const int South{ 1 };
  10.     const int East{ 2 };
  11.     const int West{ 3 };
  12. */
  13.  
  14.     int direction{ 0 };
  15.  
  16.     std::cout << "Enter direction code N - 0, S - 1, E - 2, W - 3 \n";
  17.     std::cin >> direction;
  18.  
  19.     switch (direction)
  20.     {
  21.         case Directions::North:
  22.             std::cout << "You direction is North\n";
  23.             break;
  24.         case Directions::South:
  25.             std::cout << "You direction is South\n";
  26.             break;
  27.         case Directions::East:
  28.             std::cout << "You direction is East\n";
  29.             break;
  30.         case Directions::West:
  31.             std::cout << "You direction is West\n";
  32.             break;
  33.         default:
  34.             std::cout << "Unknown direction\n";
  35.     }
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment