![]() |
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 |
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. |
Quote:
|
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. |
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.
|
| All times are GMT -5. The time now is 4:12 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC