diff --git a/main.cpp b/main.cpp index c995077..76ff6f8 100644 --- a/main.cpp +++ b/main.cpp @@ -25,22 +25,15 @@ const map morse_map = { bool should_exit = false; -bool is_exit(const string &s) { - return s.length() == 4 && tolower(static_cast(s[0])) == 'e' && - tolower(static_cast(s[1])) == 'x' && - tolower(static_cast(s[2])) == 'i' && - tolower(static_cast(s[3])) == 't'; -} - string read_input(const string &prompt) { cout << prompt; string line; - if (!getline(cin, line) || line.empty()) - return ""; - if (is_exit(line)) { + if (!getline(cin, line)) { should_exit = true; return ""; } + if (line.empty()) + return ""; return line; } @@ -119,7 +112,7 @@ public: void decode_mode() { MorseDecoder decoder; cout << "Decode mode: Enter morse sequence to decode. Press 'e' to switch to " - "encode mode, 'exit' to exit.\n\n"; + "encode mode.\n\n"; while (!should_exit) { string input = read_input("Enter morse sequence: "); @@ -171,7 +164,7 @@ void decode_mode() { void encode_mode() { MorseEncoder encoder; cout << "Encode mode: Enter text to see Morse code patterns. Press 'd' to " - "switch to decode mode, 'exit' to exit.\n\n"; + "switch to decode mode.\n\n"; while (!should_exit) { string input = read_input("Enter text to encode: ");