473,425 Members | 1,560 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,425 software developers and data experts.

Print a number in words

hi,i need a program that which prints the given number in words.
ie
if we enter 0123
the output will be as "ZERO ONE TWO THREE"[/b]
Mar 18 '10 #1
3 2851
jkmyoung
2,057 Expert 2GB
Could you show us what you have so far? Are you doing this in a function?
Mar 18 '10 #2
whodgson
542 512MB
There are a number of ways of tackling this; one way is to use switch(n) with
case: 0: case:1 //etc through 9
Typically
Expand|Select|Wrap|Line Numbers
  1. switch(n){
  2. case: 0;
  3. cout<<"zero";break;
  4. // the remaining cases follow on here 
  5. }
  6.  
You could also use
Expand|Select|Wrap|Line Numbers
  1. if(n==1)fprint("one");
  2.      else if(n==2)fprint("two");
In your case you might place your individual digits of the integer in a container such as an array or vector and then use a for loop to direct each array element to the switch() and case: statements
Mar 24 '10 #3
donbock
2,426 Expert 2GB
Your example, where a leading zero is recognized, means that the input is a string of digit characters rather than an integer. So your task is to print an output string corresponding to each character of the input string. You need to:
  • Traverse the characters of the input string
  • For each input character
    • Decide which output string is appropriate
    • Print that output string
Mar 24 '10 #4

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

Similar topics

3
by: gasturbtec | last post by:
i'm using access 2000 and have a form in which users can select reports with check boxes and click a print button to print out the selected reports. what i want to do now is place a text box on the...
3
by: isaac86 | last post by:
how to print out d words that have length 7-10? printf ( "%u characters long for %s", strlen( data)-1,data ); wLength = strlen( data)-1; if(wLength == 7||8||9||10){ ...
1
by: qwertz | last post by:
Dear All; I Am New To Perl Not So Experienced::::i Would Like To Know How I Can Compare Two Different Hashes And Print Thecommon Values In Them::it Would Be Great If Simeone Could Help Me Thanks...
3
by: vileoxidation | last post by:
Hello, and thanks for any help in advance! Basically, as the title says, I am looking for a way to print the number of times the user gave the program an input, and then also print the average of...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
5
by: sedaw | last post by:
why the print loop is not alright ? #include <stdio.h> void main() { int n, i, X, temp; printf("N=?\n"); scanf("%d",&n); for(i=1; i<n; i++) { temp=i;
4
by: JanineXD | last post by:
Hello, I already have the program ( convert number to words but only 0-999 ). I need it to be ( 0-9999 ). can you help me? package num2word; import java.util.Scanner;
4
by: lightning18 | last post by:
I have a list of incorrect words called # words and another list containing my txt file # text. I want to print the line number of the words located in the text. I get the following error for my...
1
by: deneme birki | last post by:
hello. i want to print one of random words that i defined before, on screen. but using an external .txt or .dat file. for example i add 100 words on the words.txt or words.dat file and program will...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.