program compiles, but nothing outputed

hi im writing a program to decode a morse code message. my program compiles without any error but nothing happens when i enter my code to be decoded. i think there might be something wrong in the "int main()" part of my program. i could really use some help.

im trying to decode this message:
-.. --- -. - ....... ..-. --- .-. --. . - ....... - --- ....... -.. .-. .. -. -.- ....... -.-- --- ..- .-. ....... --- ...- .- .-.. - .. -. . x

this is my code:

#include <string>
#include <vector>
#include <iostream>

using namespace std;

class Code
{public:
Code();
string decode(vector<string> message);
private:
vector<string> codewords; // codeword vector parallel to A-Z
vector<char> alpha; // vector for A-Z
vector<char> alphacode(); // function returns vector - A B C etc
vector<string> morsecode(); // function returns vector containing morse code
char decode(string c);
};

Code::Code()
{alpha=alphacode();
codewords=morsecode();
}

string Code::decode(vector<string> message)
{string temp;
for (int i=0; i<message.size(); i++)
{temp += decode(message[i]);
}

return temp;
}

char Code:: decode(string c)
{for (int i=0;i<alpha.size();i++)
{if(c == codewords[i]) //looks for codeword[i] and matches it with alpha [i]
{return alpha[i]; //returns c as a char in alpha
}
}
}

vector<char> Code::alphacode()
{vector<char> temp; // returns a vector containing the alphabet A-Z and " " and "."
for (char c='A'; c<='Z'; c++) //returns the letters
temp.push_back(c);
temp.push_back(' '); //returns the space space
temp.push_back('.'); //returns the period.
return temp;
}

vector<string> Code::morsecode()
{vector<string> temp(28); //compares c
temp[0] =".-";
temp[1] ="-...";
temp[2] ="-.-.";
temp[3] ="-..";
temp[4] =".";
temp[5] ="..-.";
temp[6] ="--.";
temp[7] ="....";
temp[8] ="..";
temp[9] =".---";
temp[10] ="-.-";
temp[11] =".-..";
temp[12] ="--";
temp[13] ="-.";
temp[14] ="---";
temp[15] =".--.";
temp[16] ="--.--";
temp[17] =".-.";
temp[18] ="...";
temp[19] ="-";
temp[20] ="..-";
temp[21] ="...-";
temp[22] =".--";
temp[23] ="-..-";
temp[24] ="-.--";
temp[25] ="--..";
temp[26] =".......";
temp[27] ="x";
return temp;
}

int main()
{vector<string> message; //this is the int main code for decode
string temp;
Code c;
cin >> temp;
while (cin.good())
{message.push_back(temp);
cin >> temp;
}
cout << c.decode(message) << endl;
}
Last edited on
Topic archived. No new replies allowed.