Morse code translator/creator

I'm making a morse code to English, calculator sort-of-thing, and my grasp of C++ has proven insufficient for this task.

It seems as though C++ doesn't in fact have a dictionary type variable, and I don't understand maps yet. Here's what I have so far, not sure if I'm doing anything right but It's a start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>

using namespace std;


string abc[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "K", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
string morse[] = {".", "_"};
// string morseCalc[] = 
int main()
{
    for(int i = 0; i <= 25; i++){
        cout << abc[i] << std:endl;
        //cout << morseCalc[i] << std::endl;
        // cout << " Got a letter " << std::endl;
    }
}


Basically I want it to get input from the user, check to see if it's a letter/word, check to see if it has a match for it in it's morse dictionary, if it does, give it back on a newline.

No need for the entire code, please explain how I might do each step.
Last edited on
How did I miss the other ":" on line 12? Also I already have std declared as the namespace don't I?
Last edited on
You have the string of 26 for alpha numeric... but only two for morse code.
Last edited on
I should have elaborated, I don't know how to assign the dot's and dashes to a letter. I thought maybe I could make a function that used either morse[1] or morse[2] to send an output of a letter, but that would require a lot of if statements and I want someone to show me how to simply compare table values and output the right one.

Example, say a table has 3 values and each value has a individual value that is unique, if I wanted to find what the value of the table's second value was how would I do that? And how would I structure the table?

Lua would simply be table = {["A"] = ".", "_"}, or something similar.

Hopefully I cleared my question, sorry I'm so bad at phrasing my coding questions.
You're fine. You coded the abc string just fine. Do the morse the same way. While you're at it, you may just for giggles and laughs throw in 1-9...

Then it should be a simple comparison from abc[number] to morse [number]
Use your loop down there in lines 11-14 to take a letter, find it in the sbc string, then print out the morse counter part.

Then you can reverse it. Search the abc string, if it's not found, search the morse string. and print out the abc counter part...


Last edited on
Topic archived. No new replies allowed.