Printing number in words

Hello,

I need to write a program in C (not C++) that recives a number as input and prints out the number in words.
For example:
input: 120
output: one hundred and twenty
Sounds nice, ah? the thing is need to do that for numbers in maximum 15 digit long.
For example:
input: 973234096500813
output: nine hundred and seventy three trillion, two hundred and thirty four billion, ninety six million, five hundred thousand, eight hundred and thirteen.

I tried to recieve the number as int type and do some manipulation on it.
The thing is that int type is too small for handling bilions. I tried to it with long\float\double but the same happens again.

Does anyone has an idea? Please note that it's C and not C++.

Thanks.
Try just reading the input as a string. You can look at each character, determine which digit it is, its location in the string, as well as the total length of the string. The total length will tell you what place the first digit is (eg 100 millions). You can then process the first digit, and as you move to the right, change the place (eg 10 millions).

Also, one thing to note is that when you write out a number in words, there are no "and"s. So instead of Two Hundred and Six, it would be Two Hundred Six. This might make the problem easier for you, although if it was an assignment and you must use "and" (even though it's not technically correct), then follow the instructions :(
Thanks you.

Do you know what is the command to get a string from the user?
How do I need to define the variable that contains the string?
Should it be: char number[15] ?
I think std::strings are better than char arrays, so
1
2
string number;
cin >> number;
Topic archived. No new replies allowed.