fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void turn_left() {
  5. cout << "left";
  6. }
  7.  
  8. void turn_right() {
  9. cout << "right";
  10. }
  11.  
  12. int main() {
  13. char direction;
  14.  
  15. do {
  16. cout << "type the direction letter [L/R]:\n";
  17. cin >> direction;
  18.  
  19. if(direction == 'L')
  20. {
  21. turn_left();
  22. break;
  23. }
  24. else if(direction == 'R')
  25. {
  26. turn_right();
  27. break;
  28. }
  29. } while (direction != 'L' && direction != 'R');
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3144KB
stdin
L
stdout
type the direction letter [L/R]:
left