fork download
  1. #include <set>
  2. #include <string>
  3. #include <iostream>
  4. //...
  5. #define PLAY 1
  6. #define STOP 0
  7. #define ERROR (-1)
  8.  
  9. int promptYN(std::string reply)
  10. {
  11. static std::set<std::string> OKResponse = {"YES", "OK", "SURE", "Y"};
  12. static std::set<std::string> StopResponse = {"NO", "QUIT", "STOP",
  13. "TERMINATE", "N", "Q"};
  14. if ( OKResponse.count(reply) == 1 )
  15. return PLAY;
  16. else
  17. if (StopResponse.count(reply) == 1)
  18. return STOP;
  19. return ERROR;
  20. }
  21.  
  22. int main()
  23. {
  24. std::cout << promptYN("OK") << '\n';
  25. std::cout << promptYN("QUIT") << '\n';
  26. std::cout << promptYN("SOMETHING ELSE") << '\n';
  27. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
1
0
-1