beginner and need help to solve my morse code / text

This is a discussion on beginner and need help to solve my morse code / text within the C++ Programming forums, part of the General Programming Boards category; I have been struggling with this a while now and cant figure out how to do it. So any help ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    1

    beginner and need help to solve my morse code / text

    I have been struggling with this a while now and cant figure out how to do it. 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. Have only studied programming for a few weeks.
    Last edited by tnkanubite; 01-20-2012 at 02:18 AM.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Morse Code(Going the other way)
    By lilbo4231 in forum C Programming
    Replies: 21
    Last Post: 06-16-2011, 03:25 AM
  2. Replies: 14
    Last Post: 11-23-2005, 07:53 AM
  3. morse code convertor
    By neandrake in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:53 AM
  4. Morse code conversion
    By viclaster in forum C Programming
    Replies: 6
    Last Post: 12-04-2003, 08:24 PM
  5. Morse Code Translator!
    By Paro in forum C++ Programming
    Replies: 4
    Last Post: 04-05-2002, 06:23 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21