Here's an idea.
Code:
/* returns string representation of number in ones column. Ex. 3 -> three */
string ones(int num);
/* returns string representation of number in tens column. Ex. 3 -> thirty */
string tens(int num);
Now break the numbers down into the hundreds form for each significant place (billions, millions, thousands, hundreds). Use the % operator to get each value and the above functions to get the string representations of those values. Then stick them all together with the terms for each significant place.
Code:
ex:
31, 821
-> 031
-> 0 -> ""
-> 3 -> thirty
-> 1 -> one
Thousand
-> 821
-> 8 -> eight (using ones column name since it's the same as hundreds)
Hundred
-> 21 -> 2 -> twenty
-> 1 -> one
Result: Thirty one thousand eight hundred twenty one.