fork download
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <exception>
  4. #include <string>
  5.  
  6. int main() {
  7. const std::unordered_map<char, std::string> CoffeeSizes = {
  8. {'S', "SMALL"},
  9. {'M', "MEDIUM"},
  10. {'L', "LARGE"}
  11. };
  12.  
  13. try {
  14. char sz;
  15. std::cout << "Enter coffee size (S or M or L): ";
  16. std::cin >> sz;
  17. std::cout << "\nYou chose: " << CoffeeSizes.at(sz) << " cup sized coffee.\n";
  18. } catch (const std::exception& e) {
  19. std::cerr << "Invalid coffee size entered.\n";
  20. return 1;
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0s 3480KB
stdin
M
stdout
Enter coffee size (S or M or L): 
You chose: MEDIUM cup sized coffee.