string array morse code translation

I cant figure out why this is not outputting the translated morse code. i am supposed to enter string text, then convert it to morse code, spaces and all by using two arrays holding the english and morse code alphabets. any hints or suggestions are appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <stdlib.h>
#include <string>
using namespace std;

void morsedisplay()
{
    cout << "A = .- " << "\t\t\t" << "B = -...\nC = -.-. " << "\t\t" << "D = -..\nE = . " << "\t\t\t" << "F = ..-.\nG = --. " << "\t\t" << "H = ....\nI = .. " << "\t\t\t" << "J = .---\nK = -.- " << "\t\t" << "L= .-..\nM = -- " << "\t\t\t" << "N = -.\nO = --- " << "\t\t" << "P = .--.\nQ = --.- " << "\t\t" << "R = .-.\nS = ... " << "\t\t" << "T = -\nU = ..- " << "\t\t" << "V = ...-\nW = .-- " << "\t\t" << "X = -..-\nY = -.-- " << "\t\t" <<
    "Z = --..\n1 = .---- " << "\t\t" << "2 = ..---\n3 = ...-- " << "\t\t" << "4 = ....-\n5 = ..... " << "\t\t" << "6 = -....\n7 = --... " << "\t\t" << "8 = ---..\n9 = ----. " << "\t\t" << "0 = -----\nStop = .-.-.- " << "\t\t" << ", = --..--\n? = ..--.. ";
}



//const int arraysize = 39;
string morse[39] = (".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----", ".-.-.-", "--..--", "..--..");
string alphabet[39] = ( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Stop", ",", "?");

int main()
{
    int counter, option;
    int length = 0;
    string english = "", coded, encoded, decoded;
    char letter, blank = ' ';
    cout.precision(2);
    cout.setf(ios::fixed | ios::showpoint);
    cout << "1 - Encode text to morse\n2 - Decode from morse to english\n3 - Display Morse code\n4 - Quit\nSelect an option, 1 - 4: ";
    cin >> option;
    //system("cls");

    switch(option)
    {
        case 1:
            morsedisplay();
            cout << "\nEnter the text that you want translated to Morse Code: ";
            //cin.clear();
            cin.ignore(100, '\n');
            getline(cin, english);

            length = english.length();
            for (int n = 0; n <= length - 1; n++)
            {
                letter = english.at(n);
                if (letter != ' ')
                {
                    for(int counter = 0; counter < 38; counter++)
                    {
                        string temporary;
                        temporary = toupper(letter);
                        if (temporary == alphabet[counter])
                        {
                            encoded = encoded + morse[counter];
                            cout << encoded;
                            //break;
                            
                        }
                    }
                }
            }
            break;
        case 2:

            break;
        case 3:
            morsedisplay();
            cout << "\n1 - Encode text to Morse\n2 - Decode from Morse to English\n3 - Display Morse code\n4 - quit\nSelect an option, 1 - 4: ";
            cin >> option;
            system("cls");
            break;
        case 4:
            exit(0);
            break;
    }
}
Last edited on
Um, where is the rest of your program?

Topic archived. No new replies allowed.