# how do you take an integer and outputed in words?

This is a discussion on how do you take an integer and outputed in words? within the C Programming forums, part of the General Programming Boards category; i need to write a program that takes an integer from -99 to +99 as input and outputs the number ...

1. ## how do you take an integer and outputed in words?

i need to write a program that takes an integer from -99 to +99 as input and outputs the number in words. If the input is outside this range, the program should print that it is outside the range.

I know there is a long way for this and a short way. Any guidance in which direction to go?

2. The way you find more understandable. If you understand them both, then go with the short way.

3. well i would like to the learn how to do the short way but at the time i cant think of how to do it. anyone have a clue?

4. Why not try a simpler program first? Write a program that takes an integer from 0 to +9 as input and outputs the number in words. If the input is outside this range, the program should print that it is outside the range.

5. I presume by the "long way", you mean a list of all numbers 0..99 written in words "zero", "one", ... "ninetynine". That's obviously feasible for a range of 0..99 (and in fact, when I was doing automated telephone systems, we did have ALL numbers from zero to ninetynine as individual numbers, rather than putting them together from components).

The shorter method involves mathematically splitting the input into tens and units. You need to use subtraction and modulo to solve that problem.

For large numbers, if you want to be able to say 1234567 as "One Million Two Hundred And Thirtyfour Thousand Five Hundred And Sixty Seven", you'd obviously not want to have a table with nearly 1.25 million numbers listed as text, so you would HAVE to use some form of math to solve the problem. It is not terribly hard.

--
Mats

6. Setup two two dimensional arrays. The first array will hold strings representing "one" thru "nineteen". The second array will hold strings representing the tens from "ten", "twenty", thirty" thru "ninety".

Next create a function, let's call it PrintStringsFromEquivalentNumeric. The decimal value to be converted is passed to this function. The function will first determine if the input numeric is less than zero. If so, it will print "Minus" and change the input numeric to an absolute value. Next the function will check to determine if the input numeric is zero. If so, print "zero" and return. Else check to determine if the input number is between one and nineteen. If so, print string from first array. Else if the input numeric is greater than nineteen, print string from second array (divide input numeric by 10) and print string from first array by modulo'ing the input number.

The PrintStringsFromEquivalentNumeric should take no more than eight lines of code. Otherwise, you're probably off on a tangent.

Popular pages Recent additions