![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2007
Posts: 13
Rep Power: 0
![]() |
how to print any number in words
helo i want to implement the following concept in my project
write a c/c++ algorithm for : accept a number from the user not greater than 6 digits and display the number in words i.e. if the input from the user is 18265 then the output should be Eighteen Thousand Two Hundred Sixty Five. if the input it 1187293 then the output should be Eleven Lac Eighty Seven Thousand Two Hundred Ninety Three. how i iplement this Regards, Amit |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,032
Rep Power: 5
![]() |
This looks like homework to me, but basically all you need is a lookup table containing strings. You'll need unique strings for 'zero' through 'nineteen', as well as the tens values ('twenty', 'thirty', etc). Then you'll need magnitude strings, such as 'hundred', 'thousand', 'million', and so on. If the number is an integer, that's about it, but if it's floating-point, you'll need 'point' in your lookup table.
From these, you can build up whatever number you want, assuming you don't exceed your maximum magnitude. You might also consider adding in 'and' where applicable. Though it's technically not correct usage, many people will say 'eight hundred and seventeen' rather than 'eight hundred seventeen'. Final hint: the division and modulus operators are your friends for this endeavor.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Yeah, I as going to say that. I did a program similar to this with Roman Numerals. It was a real bitch. I never would have figured out that the modulus operator played such a big part in it, had someone not told me.
|
|
|
|
|
|
#4 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,032
Rep Power: 5
![]() |
Quote:
Did you know four can be written as 'IIII' as well as 'IV'? I expect the former would be easier to code for, but since you need the subtractive version for higher numbers, you need to code it anyways. And what about fractions? Now those are annoying in the Roman system.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I made a money-order dispenser that did this in English and Mexican Spanish. I learned the hard way that what used to be diez y seis is now deciseis and veinte y cuatro is veinticuatro. Somewhat of a bear.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| error 3 Expected end-of-statement | m0rb1d | Other Scripting Languages | 0 | Dec 12th, 2006 10:05 AM |
| [Python] BlackJack | UnKnown X | Show Off Your Open Source Projects | 9 | Feb 20th, 2006 6:01 AM |
| First Python Programme: Fibonacci Finder | UnKnown X | Python | 2 | Dec 15th, 2005 6:19 PM |
| [tutorial] Python for programming beginners | coldDeath | Python | 30 | Dec 14th, 2005 11:35 AM |
| ftplib help please! | disAbled | Python | 1 | Jun 30th, 2005 8:05 PM |