Ok so I'm having some problems with this program I have to write as you might be able to tell it takes strings from the user either in english or morse and translates them to morse or english respectively. I got it working from English -> Morse for strings with no spaces but it terminates the concatonation after a space.
I appreciate whatever help you can give me. Written in C++ in the bloodshed compiler
//English -> morse code & vice versa 1 space per letter 3 spaces per word
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char Alpha[36] = {'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',
'1','2','3','4','5','6','7','8','9','0'};
std::string Morse[36] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",
".---","-.-",".-..","--","-.","---",".--.","--.-",".-.",
"...","-","..-","...-",".--","-..-","-.--","--..",".----",
"..---","...--","....-",".....","-....","--...","---..","----.","-----"};
string mphrase;
string ephrase;
int choice = 0;
cout<<"Please enter 1 for english to morse code translation or 2 for morse code to english translation. "<<endl;
cin>>choice;
if (choice == 1)
{
cout<<"Enter the phrase you would like to be encoded into morse."<<endl;
cin>>ephrase;
for (int i = 0; i < ephrase.length(); i++)
{
for (int h = 0; h < 36; h++)
{
if (ephrase[i] == ' ')
{
ephrase[i]++;
}
else if ( ephrase[i] == Alpha[h] )
{
mphrase += Morse[h];
mphrase += " ";
}
}
}
cout<<mphrase<<endl;
}
/* else if (choice == 2)
{
cin>>mphrase;
ephrase += Morse[x];
}
else
{
cout<<"Please enter a valid response. "<<endl;
cin>>choice;
}
cout<<mphrase;
*/
system("pause");
return 0;
}