What's up guys. My assignment is to convert user inputted text into the designated morse code value for each letter in the alphabet. I can't figure out how to read into my user's input and convert each given letter into the represented morse code value. Here is my code so far:
I pulled out the cout << of the loop to get the result only once.
Now most important is that the index of the code is not the position of the letter in the userInput, but its value (taking into account this is an ASCII code).
You can easily change the code to make it no case sensitive.
Lower case 'a' is 97 in decimal, so, subtracting 97 assigns the variable c, a 0. morseCode[0] is morse for the letter 'a'. A couple of small problems I see though. If the user types in upper and lower case, the result will be a mess. So, you a check should be done to see if the variable first is between 65 and 90. 65 is upper case 'A' and 90 is upper case 'Z'. If it is, then subtract only 65, to get the same results as with lower case. Another problem is, if the message has a space in it, as most messages will. A word shouldn't, but a message, most definitely. And, what about numbers?. Okay, you have a good start though.
Morse code only concerns itself with upper case which makes life easy.
But, if the user were to type in a lower case letter, it would mess up the program. So,
line 41 above, should be type in as int c = toupper(userInput[i]) - 97;