Need a hint

I need some help on my assignment:

The program shall be able to encode a list of letters into a list of numbers. For example, we can encode A/a as 21, B/b as 22, and C/c as 23. And, given a list of numbers in the right format of the encoding, it shall decode the original list of letter. Such as 316341 is decoded dog.

I was able to do the first part of the problem

Please enter a list of letters, and I will display you the encoded message:
dog

The list of letters 'dog' is encoded to 316341.

I would like a hint on how to
tackle the second part.

Last edited on
I was able to do it entering two digits at a time
but that's not how the professor wants it.

Here's the output

Enter by two digits:
23
C
Press any key to continue . . .

He wants a list of numbers like 316341.
Last edited on
I don't understand.. first one is for encoding.. is the second one for decoding????
Thank you @ResidentBiscuit, at first I had no idea how substr was going to help me but after an hour
of reading and seeing examples I finally understood how to use it and was able to write a solution.

@rambo1177: yes the first part is to encode a list of letters into numbers and the second part is to decode
a list of numbers into letters. I did them separately for now but I will put them together for my final solution.
There is a much nicer and cleaner way to do this without having a case: for each and every possible character. Remember that characters have a decimal value e.g. 'A' = 65 in decimal, 'a' = 97. You are to encode 'A' to = 21 as well as 'a'. To help you out I'll give you a little bit more, but 65 - x = 21, which means your 'encryption key' for lack of a better word is 44, no matter which character you are using. To make this work for lower case simply find out the difference in range between upper case and lower case (Hint I've already given you the value for 'A' and 'a' in decimal).

So now you have your encryption = -44. 'A' = 65 // 65 - 44 = 21
decryption would be +44.

Figure out the lowercase to upper and vice versa and you have a much simpler solution.

closed account (zvRX92yv)
^ This ^

And http://www.cplusplus.com/doc/ascii/
Last edited on
@clanmjc
I think I understand your hint but to me its looks like its more work to get a solution. With ResidentBiscuit hint, I was able to get a solution that was easier to get for me. Yeah its a little messy, but eh I don't mind.

Thanks for your hint though, I would like to try out your method too so I can learn another way to solve this problem.

My original method of trying to solve this problem was to ask the user to enters a list of numbers. Then the program would some how divide the int or string, of any size, into pairs of two which would then put those pairs into an element of an array such as:

(assuming the user input 316341)
numbers[] = {31,63,41}

then it does the decryption by comparing the elements of the array. But sadly, I wasn't able to get my program to do that.
Last edited on
And thanks again!
Topic archived. No new replies allowed.