Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 23rd, 2007, 12:02 AM   #1
amitpansuria
Newbie
 
Join Date: Aug 2007
Posts: 13
Rep Power: 0 amitpansuria is on a distinguished road
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
amitpansuria is offline   Reply With Quote
Old Aug 23rd, 2007, 1:25 AM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,009
Rep Power: 5 lectricpharaoh will become famous soon enough
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
lectricpharaoh is offline   Reply With Quote
Old Aug 23rd, 2007, 1:58 AM   #3
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
Quote:
Originally Posted by lectricpharaoh View Post
Final hint: the division and modulus operators are your friends for this endeavor.
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.
Booooze is offline   Reply With Quote
Old Aug 23rd, 2007, 5:32 AM   #4
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,009
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Booooze
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.
Now I'm gonna have to do a class that can convert a number to both words and Roman numerals.

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
lectricpharaoh is offline   Reply With Quote
Old Aug 23rd, 2007, 7:41 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC