473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

number to word

1
hi i am trying to convert number between 0 -----10,000 .
how can i write a code that i wil put any number and give me text. for exm:

cin>> 9552
automatically display
nine thousand five hundred fifty two

please help. thanks
Apr 29 '10 #1
6 1844
donbock
2,426 Expert 2GB
The first step is to extract each base-10 digit, starting with the most-significant. How would you approach that?
Apr 29 '10 #2
whodgson
542 512MB
if(N%10==1)cout<<"one";
else if(N%10==2)cout<<"two";... and then go on from there.
Apr 29 '10 #3
newb16
687 512MB
if(N%10==1 unless it's actually 'eleven' ) cout<<"one";
Apr 29 '10 #4
Dheeraj Joshi
1,123 Expert 1GB
cin>> 9552
automatically display
nine thousand five hundred fifty two
if number is 95524

How you want it to display?
ninety five thousand five hundred and twenty four

or

nine five five two four

This holds good if the number entered is above 50 lack or say 100 crore.

Regards
Dheeraj Joshi
Apr 29 '10 #5
donbock
2,426 Expert 2GB
Scope of requirements questions:
1. Do you have to handle negative numbers?
2. What is the maximum number of decimal digits you have to support?
3. Do you have to support decimal fractions?

There are culture-specific variations, but the way I was taught to read numbers aloud is exemplified below:
224,224,224,224 =
two hundred twenty four billion,
two hundred twenty four million,
two hundred twenty four thousand,
two hundred twenty four

The same decoding algorithm is used for each triad. You should take advantage of that regularity.

Except for the special case when N==0, your number decoder function has to do the following for each nonzero triad:
> call the triad decoder
> append the suffix appropriate for that triad.

Your triad decode function can decode each decimal digit independently except when the two least significant digits are between 10 and 19.
Apr 29 '10 #6
whodgson
542 512MB
yes newb16 completely missed that but donbrock got it in his last line.
Apr 30 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Alex Martelli | last post by:
I hesitate a bit to post this, but... on the Italian Python NG, somebody was asking whether there was any way to convert an integer number x into a string which represents it in an arbitrary base N...
5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
9
by: DS | last post by:
Whenever you use a continous form each row represents a record. Does this record have a number? If so how do you access it. Right now I have a field using auto number. But if access generates...
5
by: Jeffrey Bradshaw | last post by:
Hey everybody, I've got a VB.NET program that is trying to access a Word document and I'm having all kinds of trouble. First on is the above. I'm trying to get the number of lines in the document...
0
by: nycers_developer | last post by:
Error number 429 - COM object with CLSID {000209F0-0000-0000-C000-000000000046} is either not valid or not registered. Intermittent occurance of this error. Using Word.Global to run word macro...
6
by: Gary Wessle | last post by:
hi I have a data file with equal number of columns for each row. I need to get the number of rows and columns to allocate a matrix in gsl. getline (in, line) and parse the line for the number of...
3
by: Nhd | last post by:
I have a question which involves reading from cin and counting the number of words read until the end of file(eof). The question is as follows: Words are delimited by white spaces (blanks,...
4
by: darith | last post by:
Hi all, I want to know code in vb.net to get number of selected text in MS Word. how can we write? Please help me. I need it urgent. in textbox we just write textbox.selectedtext so we can get...
3
by: ccarter45 | last post by:
I really need help with this. Your tips are greatly appreciated: import java.util.Scanner; public class PhoneNumbers { public static void main(String args){ Scanner input; ...
2
by: alwaali | last post by:
Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.