Code:
#include <iostream>
#include <string>
#include "extendedstrings.h"
#include <windows.h>
using namespace std;
bool exit_b = 0;
string input("");
string morsecode[37] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "|"};
int main() {
while (!exit_b) {
cout<<"Type your string to convert to morse code or press e to [e]xit."<<endl;
getline(cin, input);
if (input == "e" || input == "exit" || input =="E") {
exit_b = 1;
break;
} else {
input = toLower(input);
for (int i = 0; i < input.length(); i++) {
int ascii = (int) input.at(i);
int value = 0;
if (ascii > 96 && ascii < 123)
value = ascii - 97;
else if (ascii > 47 && ascii < 58)
value = ascii - 22;
else
value = 36;
cout<<morsecode[value]<<" ";
}
}
cout<<endl<<"Time to translate english to morse code: "<<timer.getElapsedTime()<<" seconds."<<endl;
cout<<endl<<endl;
}
return 0;
}