Assignment: get integers and display in words

A

aatish19

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
 
R

Robert Gamble

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
 
F

Fred Kleinschmidt

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.
 
V

Vladimir S. Oka

Fred Kleinschmidt opined:
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>
 
S

stathis gotsis

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!
 
C

Chris McDonald

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?
 
J

Jaspreet

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

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.
 
S

santosh

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.
 
S

santosh

santosh said:
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.
 
S

stathis gotsis

Jaspreet said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top