472,962 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 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 2830
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.