I am busy with a practical. I have to enter a string or a message and have to convert it to Morse code: 'A' = .- 'B' = -... ecs.
I can do that with no problem by using a series of if statements.
for(int i = 0;i < stringvalue.length();i++)
{
if(stringvalue == 'A')
cout << ".-";
//there is 26 if statements
}
But when i enter a string, eg.
"Testing data"
Only the first part of the string is converted(test is converted) to Morse.
Why does it not convert the part after the space. If there is a space in the string it must output "/ ".
cin >>will break at the space. Look at usinggetlineinstead: en.cppreference.com/w/cpp/string/basic_string/getlineifs, maybe you could use a table (array) of Morse code values, and look up each letter in the table.