# code and decode?

• 08-04-2009, 07:50 AM
jeffrey
code and decode?
hey guys.
a simple help would do.
on this problem, it asked to decode the number to a value.
the problem here now is,
how would you distinguish 1 and 4 from 14?

Code and Decode.Create a program that asks for a value of n and generates a decoded version of the per value version of n. Use a do-while looping statement.

Ex:
Codes: a = 1; b = 2; c = 3; d = 4; e = 5; and so on
n = 145

Note:
1) do not use more than 1 variable to get the list of number values (i.e., n)
2) do not use arrays!
3) you will be the one to define the coded version of the number values
4) use only a single class and a single method, that's main()
• 08-04-2009, 08:21 AM
jeffrey
anyone?
who knows how to distinguish numbers?

example would be

input = 450

and output would be for 45=A, 0=a
so,
Aa
would be the result despite of the for 4 = e , 5 = d (eda)
• 08-04-2009, 11:17 AM
Tolls
Quote:

Originally Posted by jeffrey
anyone?
who knows how to distinguish numbers?

example would be

input = 450

and output would be for 45=A, 0=a
so,
Aa
would be the result despite of the for 4 = e , 5 = d (eda)

As you've discovered the requirements are ill-defined, it would seem. As you say, there is no way to determine if the result should be Aa or eda. Go back to whoever came up with this and ask them to clarify.

This, of course, assumes that there are more than ten letters to contend with.
• 08-06-2009, 10:56 PM
MuslimCoder
i think you shoul use something like a sentinel value.

for example if I was using it I would put them in a string. then use the Scanner to read it...
since you can pass a string to a scanner.

so for example if I have :
1 2 3 14 ...
"123/14"

Here I just used '/' as the sentinel value.
• 08-07-2009, 01:34 AM
mleather
Don't try too hard
Looking at the original post, it looks like we're thinking too hard.

If the input is 450, then the output should be three digits as well. Just assign letters to 0 to 9 and then parse one number at a time. That means you only have letters assigned, but it would satisfy the notes at the top.
• 08-07-2009, 09:18 AM
Tolls
You could be right, but I'd still go back and confirm the requirements and that they do only have to deal with 10 characters mapping to 0-9.

I know it's an exercise, but this sort of ill-defined stuff comes up all the time in the real world and failure to clarify is one of the big causes of projects going badly wrong.