Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to translate from morse code to text. please help
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tnkanubite




PostPosted: Sat Jan 21, 2012 8:55 am   Post subject: how to translate from morse code to text. please help

I should start of with say im sorry for bad spelling and code.
And also that im not sure if im posting in the correct place.
I have been struggling about 2weeks with this now and cant figure out how to do it, so needless to say im starting to feel stupid. A few weeks of studing programming and i should be able to solve this by my self i thought.
So any help would be great.
This is how it looks at the moment

code:

#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;






int main ()
{
 
  char morse[29] [7]={".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.","--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".--.-" , ".-.-", "---."};
  char text [29] [3]={ "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", "\x86", "\x84", "\x94"};
  int j, k;
  int borja=0, sok, count=0;
  unsigned int i;
 
  while (1)
  {
   
    int find_string = 0;
    int stop_string = 29;
    cout << "What do you want to do?"<<endl
    << "(3) Translate to morse code"<<endl
    << "(2) Translate from morse"<<endl
    << "(1) Exit"<<endl;
    cin >> borja;
    if (borja==3)
    {
      string skrift;
      cout << "--------------------------" <<endl
      << "You have chosen to convert" << endl
      << "From text to morse code," <<endl
      << "What should i translate? : "<<endl;
      cin >> skrift;
      cout << endl << endl << skrift << " is in morse code : ";
      unsigned int str_lenght;
      str_lenght=skrift.size();
      cout << endl;
     
      for (i=0;i<str_lenght;i++)
      {
        find_string=0;
        while (find_string < stop_string)
        {
          if (skrift[i]==text[find_string][0])
          {
            cout << morse[find_string] << " ";
            break;
          }
            else
            find_string = find_string+1;
        }
      }
    }
   
    else if (borja==2)
    {
        char skrift[50];
      cout << "--------------------------" <<endl
      << "You have chosen to convert" << endl
      << "from morse code to text," <<endl
      << "What should i translate? : "<<endl;
      skrift.getline(skrift, 50, endl) >> skrift;
      cout << endl << endl << skrift << "is in text : ";
      unsigned int str_lenght;
      str_lenght=50;
      cout << endl;
     
      for (i=0;i<str_lenght;i++)
      {
        find_string=0;
        while (find_string < stop_string)
        {
          if (skrift[i]==morse[find_string][0])
          {
            cout << text[find_string];
            break;
          }
          else
          {
            find_string = find_string+1;
          }
        }
      }
     
    }
    else
      break;
   
    cout << endl << endl << endl << endl;
  }
  cin.get();             
  return 0;
}


the first from text to morse i finaly solved it. but the other way around was abit difficult for me. The getline dont work. So if anyone out there can help me solve this or point me in the right way.
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Mon Jan 30, 2012 1:19 am   Post subject: RE:how to translate from morse code to text. please help

what is your compiler? I would be able to help.
Raknarg




PostPosted: Mon Jan 30, 2012 4:33 pm   Post subject: RE:how to translate from morse code to text. please help

Out of curiosity, why do you use get line only for morse code? Is the idea that it's supposed to be only one word at a time?
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: