Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 30th, 2003, 03:33 AM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default generating words

how can i generate numbers in the form of words
like:
1250----------> one thousand two hundred and fifty
how can i do this ??????
Reply With Quote
  #2 (permalink)  
Old September 30th, 2003, 12:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you'd write a program that does pretty much what you do as a person.

You should go right-to-left, since you don't know what place-value any digits on the left have until you count how many places they are from the right.

You'd check the right-most two digits first, since "22" is parsed differently from "12", etc. All other number words are of a specific format, namely "<number> <value>", e.g. "three thousand".

The way I'd handle it is to write a function that converts at most a three-digit number. From "zero" to "nine hundred ninety nine".

The reason being is that for all other place values, you'll only need to generate this name and append a place value modifier.

For example: 1,234,567,890 is broken up into four three-digit parts: 001 234 567 890.

Your application simply needs to convert each three digit part to text and append an additional modifier. Your final answer will be the concatenation of all these strings.

 threeDigitToText(001) + " billion " +
 threeDigitToText(234) + " million " +
 threeDigitToText(567) + " thousand " +
 threeDigitToText(890)


Since this sounds suspiciously like a homework assignment, I'm not going to write any the code, but this should be enough to get you started.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trimming Words Nicky_uk Classic ASP Databases 5 February 21st, 2008 02:06 PM
spacing in between the words ramank Classic ASP Basics 1 November 20th, 2006 07:25 AM
why I can't use Chinese words? cash JSP Basics 4 February 19th, 2004 10:47 PM
why I can't use Chinese words? cash Pro JSP 1 February 17th, 2004 02:40 PM
generating words kozam C++ Programming 1 September 30th, 2003 12:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.