473,549 Members | 4,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

number to word

1 New Member
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 1850
donbock
2,426 Recognized Expert Top Contributor
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 Contributor
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 Contributor
if(N%10==1 unless it's actually 'eleven' ) cout<<"one";
Apr 29 '10 #4
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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 Contributor
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
2129
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 (given a sequence with a len of N that gives the digits to use) as "a single expression". I haven't found a really general way, much less a clear...
5
3172
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 to code a solution to this it'll probably be done in ASP on a web server, unless there's a significantly better way. I'm looking for a way to...
9
9059
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 its own number for that row I'd like to use that. Thanks DS
5
4641
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 and when I try docWord.BuiltInDocumentProperties("NUMBER OF LINES") it returns an Object. When I look in the debugger, it is of type...
0
20469
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 in vb .net application. CODE: Friend WordGlobal_definst As Object
6
3258
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 spaces then add one to get the number of words then number_of_rows = 1; while getline (in, line) and number_of_rows++ does the number of rows I...
3
6344
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, tabs, linefeeds, returns). It will print 3 pieces of information before exit: the first word, the last word, and the number of words read, with one...
4
1526
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 number of selected text but in MS word i don't understand how can we write to get number selcted text in MS word? one problem in textbox if we want...
3
23777
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; Scanner scan = new Scanner(System.in);//get user input
2
3399
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 results of the analysis are to be stored in a suitable data structure. The main task in this project is to design a suitable ADT (call it WAnalysis)...
0
7723
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.