473,491 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Print a number in words

1 New Member
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 2852
jkmyoung
2,057 Recognized Expert Top Contributor
Could you show us what you have so far? Are you doing this in a function?
Mar 18 '10 #2
whodgson
542 Contributor
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 Recognized Expert Top Contributor
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
3823
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
1457
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
1834
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
1984
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
2875
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
3426
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
19783
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
1764
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
2610
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
7118
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
6980
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
7192
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
7364
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
5452
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,...
1
4886
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...
0
4579
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
3087
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
1397
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 ...

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.