# Thread: Number to Word (Billions)

1. Well, now we're even - because I don't understand the above program.

I would throw this "fish" back, and go study the last program before this. That one was the way to go.

This one is not a "keeper".

You need an array of strings that will associate the word "two" (for instance), with the word[][] array row 2. Like the last program had.

Then, when you are scanning through a number, and you come to the digit 2, you know where to find the right word - in word[2], which equals, LOOKY THERE, IT'S A MIRACLE!!, "two".

There are other ways to do this, but they pretty much follow this same scheme or organization. Word[][] would be a 2 dimension char array with entries like: "zero", "one", "two", "three", "four", etc., which would correspond with word[0], word[1], word[2], word[3], word[4], in rows. (So word[0] is a whole row, not just one char like word[0][0], would be.)

Let's look at word[0]:

It has 6 subscripts (spaces), because "seven" has 5 letters, and then we need one char for the end of string char: '\0', so it's elevated to string status, not just a few char's.

So word[0][0] == 'z';
word[0][1] == 'e';
word[0][2] == 'r';
word[0][3] == 'o';
word[0][4] == '\0';

But - very sweetly, word[0] == "zero", (yes, the whole string!).

That's what you need - that's what you need to study - not this last misguided effort.

And if I were asking for help on an English help forum, I'd have the program in English, or some sub-titles in English. Obviously, you speak it well enough to do that.

P.S.
Ignore comma's. You can't rely on numbers always having them (2,000 does, but 2000 doesn't), and you don't need to do any special processing for them. The word to remember for comma's is "continue".

2. If you don't understand the version that uses tables instead of switch statements then you should give yourself more time to understand it. It will be far more productive for you to learn how to do it with tables than to use switch statements. Feel free to ask tons of questions about it.

You will definitely spend at least as long trying to get it to work any other way. But if you spend the time learning to do it with tables you'll have gained so much more knowledge along the way. Trust me it will take less time to learn it than you think. Also your teacher will be that much happier grading a shorter program that you'll probably get a better mark.

3. Originally Posted by Perspective
by the way, you should only have "and" after a decimal place. 3,485 should be "Three thousand four hundred eighty five" not "three thousand four hundred and eighty five".
Only in US English.

4. And Canadian English (no "and").

5. Wow, I had no idea any cultures omitted the 'and'.

6. Originally Posted by Brian
Only in US English.
"and" marks the decimal place. In what country would you say "four hundred and eighty two dollars and eighty six cents" ? That's just bad english.

7. Originally Posted by Perspective
"and" marks the decimal place. In what country would you say "four hundred and eighty two dollars and eighty six cents" ? That's just bad english.
That's what you do in England, except it would be "four hundred and eighty two pounds and eighty six pence". At least if you speak "proper English".

--
Mats

8. I think that myphilosofi should follow whatever were the given requirements.

Originally Posted by Perspective
"and" marks the decimal place. In what country would you say "four hundred and eighty two dollars and eighty six cents" ? That's just bad english.
The problem is that you first propose a rule ("and" marks the decimal place), but the reasoning does not support the rule, except in the case where there is a decimal place. In that sense I see no wrong in rendering the amount as "three thousand, four hundred and eighty five dollars". It also seems correct to render \$482.86 as "four hundred and eighty two dollars, and eighty six cents".

9. Originally Posted by laserlight
I think that myphilosofi should follow whatever were the given requirements.

The problem is that you first propose a rule ("and" marks the decimal place), but the reasoning does not support the rule, except in the case where there is a decimal place. In that sense I see no wrong in rendering the amount as "three thousand, four hundred and eighty five dollars". It also seems correct to render \$482.86 as "four hundred and eighty two dollars, and eighty six cents".

I don't see how the reasoning doesn't support the rule, but anyway, saying "A and B, and C" is in general bad grammar. It should be "A, B, and C".

10. Originally Posted by Perspective
I don't see how the reasoning doesn't support the rule, but anyway, saying "A and B, and C" is in general bad grammar. It should be "A, B, and C".
That may be if we simply talk about grammar in generic terms. However, if we talk about "reading numbers out loud", then the proper British English way to say 123 is "One hundred and twenty three". If you want to say "Between 123 and 125", then, grammar or not, you should say "Between one hundred and twenty three and one hundred and twenty five".

--
Mats

11. Originally Posted by Perspective
I don't see how the reasoning doesn't support the rule, but anyway, saying "A and B, and C" is in general bad grammar. It should be "A, B, and C".
I may be something of an amateur C and C++ language lawyer, but I am definitely not an English language lawyer, so I cannot substantiate why I think that "A and B, and C" is valid

Fortunately, I have a way to substantiate my first claim. We can agree that "A, B, and C" is valid. So, we can agree that "four hundred, eighty two dollars, and eighty six cents" is valid. Likewise, we can agree that "one thousand, four hundred, and eighty two dollars" is valid. That implies that the reasoning behind the '"and" marks the decimal place' rule is flawed, unless you propose that "A, B, and C" is invalid in this case.

12. >Likewise, we can agree that "one thousand, four hundred, and eighty two dollars" is valid.

But I don't agree with this point. I think it should be "one thousand four hundred eighty two dollars". So my rule isn't violated by what I've claimed (in this case it's not "A, B, and C", it's only "A"). I guess it's different in british english.

13. Originally Posted by Perspective
I guess it's different in british english.
Yes, it seems that that is the case.

14. ## Hey, it's me again

one of my classmates said to use "atol"

does anyone have any idea how and why?

thanks!

15. Originally Posted by myphilosofi
one of my classmates said to use "atol"

does anyone have any idea how and why?
Your classmate probably thought that using atol() to convert the numeric string input to a long int would allow the method you originally wanted to use to work. The problem of removing the commas remain, and you still have the account for the decimal place. Oh, and as before, the range that you are required to handle exceeds the guaranteed range of a long, so the approach is not guaranteed to work in the first place.

Personally, I feel that just handling it as a numeric string is best.

Popular pages Recent additions