Don't listen to
Fredbill et. al. they're wasting your time.
The issue is how you are thinking about the number. Which is what
LowestOne is talking about.
Notice that the only difference between
123 ("one hundred twenty three") and 123,000 ("one hundred twenty three thousand") is the word "thousand" at the end.
This is true of any power of 10
3.
What you have so far
You've got your basic formula for every group of three digits on lines 37 through 55. Put that into a function.
Now all you have to do is break your number up by groups of three (powers of 1000), and call the function for each group. Remember, you'll have to work
backwards, because you want to write the millions before the thousands before the zeros.
123,456,789
one hundred twenty three million
four hundred fifty six thousand
seven hundred eighty nine
2,000,013
two thousand
thirteen
[edit] Working backwards really means that you have to grab the higher groups of three first.
1 2 3 4 5 6 7 8 9 10 11 12
|
int power_index = 1;
int power_value = 1000;
while ((number / power_value) != 0)
{
power_value *= 1000;
power_index += 1;
}
power_value /= 1000;
power_index -= 1;
// now power_value is one of 0, 1000, 1000000, 1000000000, ...
// and power_index is one of 0, 1, 2, 3, ...
|
Now you can use
power_value to divide
number for the first three digits to pass to your function. Use
power_index as an index into an array of the names to tack onto the end ("thousand", "million", etc).
Don't forget to remove those three digits from
number before the next time through the loop.
Hope this helps.