system("cls");
cout << "'.' equals a dot and '-' equals a dash." << endl;
cout << "You MUST enter a '*' to end letters and a space in between words." << endl;
cout << "Please enter morse code to de-code: ";
cin.ignore();
getline (cin, message3);
while (o < message3.length()) {
for (o = 0; o < message3.length(); o++) {
t = message3[o];
if (t != '*' && t != ' ' && (t == '.' || t == '-')) {
temp += t;
break;
}
}
w = message3.length();
if (w > 5) {
out1 += "?";
break;
}
if (temp == ".-") {
out1 += "a";
break;
}
else if (temp == "-...") {
out1 += "b";
break;
}
else if (temp == "-.-.") {
out1 += "c";
break;
}
else if (temp == "-..") {
out1 += "d";
break;
}
else if (temp == ".") {
out1 += "e";
break;
}
else if (temp == "..-.") {
out1 += "f";
break;
}
else if (temp == "--.") {
out1 += "g";
break;
}
else if (temp == "....") {
out1 += "h";
break;
}
else if (temp == "..") {
out1 += "i";
break;
}
else if (temp == ".---") {
out1 += "j";
break;
}
else if (temp == "-.-") {
out1 += "k";
break;
}
else if (temp == ".-..") {
out1 += "l";
break;
}
else if (temp == "--") {
out1 += "m";
break;
}
else if (temp == "-.") {
out1 += "n";
break;
}
else if (temp == "---") {
out1 += "o";
break;
}
else if (temp == ".--.") {
out1 += "p";
break;
}
else if (temp == "--.-") {
out1 += "q";
break;
}
else if (temp == ".-.") {
out1 += "r";
break;
}
else if (temp == "...") {
out1 += "s";
break;
}
else if (temp == "-") {
out1 += "t";
break;
}
else if (temp == "..-") {
out1 += "u";
break;
}
else if (temp == "...-") {
out1 += "v";
break;
}
else if (temp == ".--") {
out1 += "w";
break;
}
else if (temp == "-..-") {
out1 += "x";
break;
}
else if (temp == "-.--") {
out1 += "y";
break;
}
else if (temp == "--..") {
out1 += "z";
break;
}
else if (temp == ".----") {
out1 += "1";
break;
}
else if (temp == "..---") {
out1 += "2";
break;
}
else if (temp == "...--") {
out1 += "3";
break;
}
else if (temp == "....-") {
out1 += "4";
break;
}
else if (temp == ".....") {
out1 += "5";
break;
}
else if (temp == "-....") {
out1 += "6";
break;
}
else if (temp == "--...") {
out1 += "7";
break;
}
else if (temp == "---..") {
out1 += "8";
break;
}
else if (temp == "----.") {
out1 += "9";
break;
}
else if (temp == "-----") {
out1 += "0";
break;
}
else {
out1 += "?";
break;
}
if (isspace(t)) {
out1 += " ";
break;
}
temp.clear();
}
morsedecop:
system("cls");
cout << out1 << endl;
cout << "Please choose an option: " << endl;
cout << "1. Main Menu" << endl;
cout << "2. Exit Program" << endl;
cout << "Choice: ";
cin >> l;
switch (l) {
case 1:
goto begin;
case 2:
exit(1);
default:
cout << l << " is not an option; please ty again." << endl;
system("pause");
goto morsedecop;
}
case 3:
exit(1);
default:
cout << i << " is not an option; please try again." << endl;
system("pause");
goto begin;
}
Morse Code De-code HELP
Page 1 of 14 Replies - 261 Views - Last Post: 06 February 2012 - 02:09 PM
Topic Sponsor:
#1
Morse Code De-code HELP
Posted 06 February 2012 - 01:10 PM
So I'm trying to make a program that does ciphers and also morse code and everything works perfectly except the decoding of the morse code part. The code for that part is below... Also any variables you see undeclared are declared elsewhere.
Replies To: Morse Code De-code HELP
#2
Re: Morse Code De-code HELP
Posted 06 February 2012 - 01:18 PM
Quote
everything works perfectly except the decoding of the morse code part. The code for that part is below... Also any variables you see undeclared are declared elsewhere.
Okay *how* does the decoding bit not work perfectly? What is it doing versus what should it be doing? If you are providing a small section of your total code it always helps to be extremely verbose and clear on what the problem is, how you know it is a problem, and what you have tried! You know, the typical "help us to help you".
#3
Re: Morse Code De-code HELP
Posted 06 February 2012 - 01:42 PM
Sorry I suppose I should have been more clear. Okay so basically it should read the input and put it char by char into another string and stop putting it in the string if the char is an '*'. Then it should check all 36 possibilities of morse code that I have in the code to see if the string that had the chars put in one by one equals any of them. If you it does then it puts a letter in another string and then goes back and does it again until it has read the entire input. Then it should output the de-coded message.
Sorry accidentally posted that without finishing... So anyway when it shows the output it's blank every time no matter what....
Sorry accidentally posted that without finishing... So anyway when it shows the output it's blank every time no matter what....
#4
Re: Morse Code De-code HELP
Posted 06 February 2012 - 01:54 PM
Saw the gotos, stopped reading. Seriously, goto?!?
Make a function. Called something like string morseDecode(const string &);. Now, feed it some test data. What do you expect, what do you get?
You first need to break on the spaces, that will be your words. Then break on the '*', that will be a complete word.
Perhaps:
Make a function. Called something like string morseDecode(const string &);. Now, feed it some test data. What do you expect, what do you get?
You first need to break on the spaces, that will be your words. Then break on the '*', that will be a complete word.
Perhaps:
char morseDecodeChar(const string &);
string morseDecodeWord(const string &);
string morseDecode(const string &);
//...
char morseDecodeChar(const string &s) {
if (s == ".-") { return 'a'; }
if (s == "-...") { return 'b'; }
if (s == "-.-.") { return 'c'; }
if (s == "-..") { return 'd'; }
if (s == ".") { return 'e'; }
if (s == "..-.") { return 'f'; }
if (s == "--.") { return 'g'; }
if (s == "....") { return 'h'; }
if (s == "..") { return 'i'; }
if (s == ".---") { return 'j'; }
if (s == "-.-") { return 'k'; }
if (s == ".-..") { return 'l'; }
if (s == "--") { return 'm'; }
if (s == "-.") { return 'n'; }
if (s == "---") { return 'o'; }
if (s == ".--.") { return 'p'; }
if (s == "--.-") { return 'q'; }
if (s == ".-.") { return 'r'; }
if (s == "...") { return 's'; }
if (s == "-") { return 't'; }
if (s == "..-") { return 'u'; }
if (s == "...-") { return 'v'; }
if (s == ".--") { return 'w'; }
if (s == "-..-") { return 'x'; }
if (s == "-.--") { return 'y'; }
if (s == "--..") { return 'z'; }
if (s == ".----") { return '1'; }
if (s == "..---") { return '2'; }
if (s == "...--") { return '3'; }
if (s == "....-") { return '4'; }
if (s == ".....") { return '5'; }
if (s == "-....") { return '6'; }
if (s == "--...") { return '7'; }
if (s == "---..") { return '8'; }
if (s == "----.") { return '9'; }
if (s == "-----") { return '0'; }
return '?';
}
#5
Re: Morse Code De-code HELP
Posted 06 February 2012 - 02:09 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|