Hi everybody!
I have to make an algorithm which gets a number and converts it in 4 different languages in letters, I mean e.g. the number 102 to be converted in one hundred-two; ein hundert zwei; cent deux; cento due;
Actually as for the english I can make an algorithm. It will be something like this:
we have our number nr as integer
string number = "";
get an array of strings digits ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", 'ten', 'eleven', 'twelve', 'thirteen','fourteen','fifteen', 'sixteen', 'seventeen','eighteen','nineteen']
get another array of strings: array1 ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
if (nr < 20)
number = digits[nr]
else
if (nr % 10 == 0)
number = array1[nr / 10 - 2]
else number = array1[nr / 10 - 2] + "-" + digits[nr % 10]
this idea goes then for numbers that are bigger or equal to one hundred.
My problem is that writing this for every language seems not like a good idea, but I couldn't find another way to do it. Can anybody help me?
P.S. sorry for the mistakes in coding, but I was in hurry and some of them, I made with copy paste.
Any help would be very appreciated.
Thanks
I have to make an algorithm which gets a number and converts it in 4 different languages in letters, I mean e.g. the number 102 to be converted in one hundred-two; ein hundert zwei; cent deux; cento due;
Actually as for the english I can make an algorithm. It will be something like this:
we have our number nr as integer
string number = "";
get an array of strings digits ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", 'ten', 'eleven', 'twelve', 'thirteen','fourteen','fifteen', 'sixteen', 'seventeen','eighteen','nineteen']
get another array of strings: array1 ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
if (nr < 20)
number = digits[nr]
else
if (nr % 10 == 0)
number = array1[nr / 10 - 2]
else number = array1[nr / 10 - 2] + "-" + digits[nr % 10]
this idea goes then for numbers that are bigger or equal to one hundred.
My problem is that writing this for every language seems not like a good idea, but I couldn't find another way to do it. Can anybody help me?
P.S. sorry for the mistakes in coding, but I was in hurry and some of them, I made with copy paste.
Any help would be very appreciated.
Thanks