By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,062 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,062 IT Pros & Developers. It's quick & easy.

Assignment: get integers and display in words

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a

<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

P: n/a
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

P: n/a
<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

P: n/a
"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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.