|
-
November 11th, 2009, 02:21 PM
#1
Again pls help
I am trying to decrypt a morsecode to letter's, the input should be morsecode and output should be letter's i have been trying for the last 4-5 hour's but i can' get it right, i know something is wrong with the 2nd for loop since is only looping trough the first character in the morse code , but how do i change that.
here is the code:
Code:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
string morse(string a);
int main()
{
string ord;
cout<< "\nwrite your morsecode " <<endl;
cin>>ord;
cout<<"the morse code decrypted is "<<morse(ord);
system("PAUSE");
return 0;
}
string morse(string a)
{
char g;
string z[30]={".- ","-... ","-.-. ","-.. ",". ","..-. ","--. ",".... ",".. ",".--- "
,"-.- ",".-.. ","-- ","-. ","--- ",".--. ","--.- ",".-. ","... ","- "
,"..- ","...- ",".-- ","-..- ","--.. ",".--.- ",".-.- ","---. "};
string u[30]={"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","Å","Ä","Ö"};
string klart="";
for (int i = 0;i <a.size();i++)
{
char f =a [i];
for (int j = 0; j <=29;j++)
{
string tmp=z[j];
g=tmp[0];
if(g==f)
{
klart=klart +u[j];
}
}
}
return klart;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|