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

Assignment: get integers and display in words

Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two

Apr 12 '06 #1
9 4161
aa******@gmail.com wrote:
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two


Why are you posting these here? If you have a question about the C
language, please articulate it clearly. If you are looking for people
to do your homework for you, buzz off.

Robert Gamble

Apr 12 '06 #2

<aa******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two


Gee, even the statement of the homework is wrong - a thousEnd time wrong.

Here's a start:

#include <stdio.h>

int main() {

return 0;
}

You fill in the rest; then we'll tell you where you haven't done it
correctly.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Apr 12 '06 #3
Fred Kleinschmidt opined:

<aa******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two

Gee, even the statement of the homework is wrong - a thousEnd time
wrong.

Here's a start:

#include <stdio.h>

int main() {


For a start:

int main(void) {

is better (and slightly different). ;-) ;-)
return 0;
}

You fill in the rest; then we'll tell you where you haven't done it
correctly.


--
Prepare for tomorrow -- get ready.
-- Edith Keeler, "The City On the Edge of Forever",
stardate unknown

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 12 '06 #4
<aa******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two


Here is a function which prints out a decimal, correct it if it has any
mistakes:

void print_dec(unsigned int number)
{
if (number/10)
print_dec(number/10);
printf("%d",number % 10);
fflush(stdout);
}

That is a start i think. Good luck!
Apr 12 '06 #5
"stathis gotsis" <st***********@hotmail.com> writes:
<aa******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googleg roups.com...
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two
Here is a function which prints out a decimal, correct it if it has any
mistakes: void print_dec(unsigned int number)
{
if (number/10)
print_dec(number/10);
printf("%d",number % 10);
fflush(stdout);
} That is a start i think. Good luck!

I appreciate that you didn't wish to give away an answer to a likely
homework question, but did you read/understand the question?

--
Chris.
Apr 12 '06 #6

Chris McDonald wrote:
"stathis gotsis" <st***********@hotmail.com> writes:
<aa******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googleg roups.com...
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two

Here is a function which prints out a decimal, correct it if it has any
mistakes:

void print_dec(unsigned int number)
{
if (number/10)
print_dec(number/10);
printf("%d",number % 10);
fflush(stdout);
}

That is a start i think. Good luck!

I appreciate that you didn't wish to give away an answer to a likely
homework question, but did you read/understand the question?

--
Chris.


I guess the print_dec() function can be used to slice off individual
digits from the number to then move onto displaying it in words. For
example, 672 would be shown as Six (after getting individual digit from
the number using print_dec and using an enum to display six for 6)
hundred (another function which would keep track of which place->tens,
hundreds, thousands, etc) seventy (with help from print_dec and enum)
two (print_dec and enum).

As Stathis pointed out, this is just a start and not the whole program.

Apr 13 '06 #7
aa******@gmail.com wrote:
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two


Get the number, convert it to it's string form, allocate a buffer of
pointers.
Starting from the units place of the number, determine it's digit,
point the first pointer of the buffer to a string built into the code
having the English name of the digit. Also keep track of the decimal
position and if neccessary, point adjacent pointers to appropriate
strings.

After a certain upper limit, the conversion to words becomes
ridiculous, but before that limit is reached you'll exceed the range of
C's int and long types.

Apr 13 '06 #8
santosh wrote:
aa******@gmail.com wrote:
Write a program that asks the user to input any amount as an integer
number and display it in words
Sample output:
Enter any amount : 4562
Four thousend five hundred sixty two


Get the number, convert it to it's string form, allocate a buffer of
pointers.
Starting from the units place of the number, determine it's digit,
point the first pointer of the buffer to a string built into the code
having the English name of the digit. Also keep track of the decimal
position and if neccessary, point adjacent pointers to appropriate
strings.


I forgot to add:
After you've gone through the number, you'll have to print out the
strings pointed to by the pointers in reverse order.

Apr 13 '06 #9
"Jaspreet" <js***********@gmail.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...

Chris McDonald wrote:
"stathis gotsis" <st***********@hotmail.com> writes:
<aa******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googleg roups.com...
> Write a program that asks the user to input any amount as an integer
> number and display it in words
> Sample output:
> Enter any amount : 4562
> Four thousend five hundred sixty two

Here is a function which prints out a decimal, correct it if it has any
mistakes:

void print_dec(unsigned int number)
{
if (number/10)
print_dec(number/10);
printf("%d",number % 10);
fflush(stdout);
}

That is a start i think. Good luck!

I appreciate that you didn't wish to give away an answer to a likely
homework question, but did you read/understand the question?

--
Chris.


I guess the print_dec() function can be used to slice off individual
digits from the number to then move onto displaying it in words. For
example, 672 would be shown as Six (after getting individual digit from
the number using print_dec and using an enum to display six for 6)
hundred (another function which would keep track of which place->tens,
hundreds, thousands, etc) seventy (with help from print_dec and enum)
two (print_dec and enum).


Yes, that is what i roughly had in mind but on second thought i feel it will
not lead to an elegant or simple solution. Other ways of solving this
problem could be much better as a matter of fact. So, Chris may be right
after all.
Apr 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: dan | last post by:
without stirring the pot too much -- could someone please point me to whatever documentation exists on the philosophy, semantics, and practical implications of how Python implements the...
23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
5
by: Haoyu Zhang | last post by:
Dear Friends, Python assignment is a reference assignment. However, I really can't explain the difference in the following example. When the object is a list, the assignment seems to be a...
3
by: Matt | last post by:
<% hour = Request("controlname") %> will yield the following error: Microsoft VBScript runtime (0x800A01F5) Illegal assignment: 'hour' However, if I declare hour, then it is fine. <% Dim...
43
by: michael.f.ellis | last post by:
The following script puzzles me. It creates two nested lists that compare identically. After identical element assignments, the lists are different. In one case, a single element is replaced. In...
6
jlandbw04
by: jlandbw04 | last post by:
Okay. Here's the deal. I have this assignment for college that has me completely puzzled. I need this assignment to do the following: 1. input 12 integers into an array from the user. 2. output...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.