473,397 Members | 2,116 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,397 software developers and data experts.

Input numbers output words problem

Hello,i'm wondering if anyone can help me. The c program needs to input any number from 1-999 and it must output whatever number was input in words.i have made a start on the hundredths and tens...can anyone help me with wht i can use to input the data? When i compile and run the program,only if i put in a single digit then it prints (eg if i put in 5) five hundred, for 3 digit numbers it doesnt print anything.I think the problem is inputing the numers,can anyone help me with how to input the numbers?(what ways can i use?) Can You tell me if anything is wrong with what i already have also?thank you very much...
here is the code
Mar 7 '08 #1
6 3767
i think the array should only have one number(i have 3 in the array above),its supposed to just be a 3 digit number..one number.can anyone help me with tht..thnx
Mar 7 '08 #2
Parul Bagadia
188 100+
Yaeh even i think so; you should have an array having only one number in it; abd have some variable so that u can access diff. places; as in units place tens place and so on......
Because in case of three numbers; they themselves will have some places ; its not given that they all should be a single digit no.
And anyhow you are converting a single no.
Mar 7 '08 #3
yes,i know tht.but i tried using the array with one number in it..it still didnt work.i need to assign values(ones,tens,hundredths) .i need to tell the computer tht in the case of 768,7 is a hundred,6 is a ten,and 8 is a one....can anyone plz tell how i can do tht.i've been reading and i cant find a way to do it.
Mar 7 '08 #4
yes,i know tht.but i tried using the array with one number in it..it still didnt work.i need to assign values(ones,tens,hundredths) .i need to tell the computer tht in the case of 768,7 is a hundred,6 is a ten,and 8 is a one....can anyone plz tell how i can do tht.i've been reading and i cant find a way to do it.thank you very much
Mar 7 '08 #5
MACKTEK
40
I am thinking of a different method to do this.

User inputs a number (in text).
Convert to an Integer i (perhaps you can skip that if user enters integer directly)

Then take int i and divide it by the maximum "place" value and cast it.
For example
hund=int(i/100);
// this casts a division that would usually not be a whole number value into an integer... it does not round up, simply casts aside anything to the right of the decimal point.

If you print hund it will be a single digit.

for example if the user enters 955... int(955/100) will be 9.

The next step is to subtract 9*100 from the total.

Leaving you with 55.

You would then repeat the cast (i/10) etc...

that should help you to get the numbers you need.

Converting it to text can be done with judicious use of if statements , case statement, maybe even enums combined.
For example:
You could declare an Enum that enumerates the text from "one hundred to nine hundred"

You will have to take into account that normal English does not usually pronounce the hundreds, tens place etc if they do not exist.
Also, as you already noticed, from 0 to 19 is a special case.

Hope that helps.
Mar 8 '08 #6
hey,thank you. i have to input the number rather than the text but i got the idea.i'll work wit it..thank you
I am thinking of a different method to do this.

User inputs a number (in text).
Convert to an Integer i (perhaps you can skip that if user enters integer directly)

Then take int i and divide it by the maximum "place" value and cast it.
For example
hund=int(i/100);
// this casts a division that would usually not be a whole number value into an integer... it does not round up, simply casts aside anything to the right of the decimal point.

If you print hund it will be a single digit.

for example if the user enters 955... int(955/100) will be 9.

The next step is to subtract 9*100 from the total.

Leaving you with 55.

You would then repeat the cast (i/10) etc...

that should help you to get the numbers you need.

Converting it to text can be done with judicious use of if statements , case statement, maybe even enums combined.
For example:
You could declare an Enum that enumerates the text from "one hundred to nine hundred"

You will have to take into account that normal English does not usually pronounce the hundreds, tens place etc if they do not exist.
Also, as you already noticed, from 0 to 19 is a special case.

Hope that helps.
Mar 8 '08 #7

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

Similar topics

7
by: MM | last post by:
Hi there, How can I change my code (below) so that I use an "input argument" to specify the file name of the input file? For example, if I compile the code and that the application then gets the...
10
by: Matt | last post by:
Ok, so the exercise is to: Write a program that prints its input one word per line. Does this mean so that when I prest ^Z(ctrl-z) to exit the program if I were to do this: Hey you It...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
3
by: charlz | last post by:
im been having difficuties in reading and storing from an input file. the problem goes like this: Write a program that reads in a whole bunch of words from all file (each word is no more than 20...
1
by: Imnew2c | last post by:
need help with logic of a pgm... pgm is to print the following output... This computer generated string contains ___letters:,____ A,_____B, ....._____Z. This is the output. The blanks are...
10
by: strife | last post by:
Hi, This is a homework question. I will try to keep it minimal so not to have anyone do it for me. I am really just stuck on one small spot. I have to figure out the highest number from a users...
3
by: powerej | last post by:
writing a program that asks how many numbers the users want to enter, then input an integer for the amount of numbers said, output: number of integers entered, sum of them, average of them, maximum...
14
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num;...
209
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from...
1
by: randysimes | last post by:
I have a program to read in words and sort those words into lexicographical order. The problem I have is that it reads the input file endlessly. I know it does not reach the output section because...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.