Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Assignment: get integers and display in words

Reply
Thread Tools

Assignment: get integers and display in words

 
 
aatish19@gmail.com
Guest
Posts: n/a
 
      04-12-2006
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

 
Reply With Quote
 
 
 
 
Robert Gamble
Guest
Posts: n/a
 
      04-12-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Fred Kleinschmidt
Guest
Posts: n/a
 
      04-12-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
Vladimir S. Oka
Guest
Posts: n/a
 
      04-12-2006
Fred Kleinschmidt opined:

>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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>

 
Reply With Quote
 
stathis gotsis
Guest
Posts: n/a
 
      04-12-2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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!


 
Reply With Quote
 
Chris McDonald
Guest
Posts: n/a
 
      04-12-2006
"stathis gotsis" <(E-Mail Removed)> writes:

><(E-Mail Removed)> wrote in message
>news:(E-Mail Removed) 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.
 
Reply With Quote
 
Jaspreet
Guest
Posts: n/a
 
      04-13-2006

Chris McDonald wrote:
> "stathis gotsis" <(E-Mail Removed)> writes:
>
> ><(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed) 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.

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      04-13-2006
(E-Mail Removed) 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.

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      04-13-2006
santosh wrote:
> (E-Mail Removed) 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.

 
Reply With Quote
 
stathis gotsis
Guest
Posts: n/a
 
      04-13-2006
"Jaspreet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> Chris McDonald wrote:
> > "stathis gotsis" <(E-Mail Removed)> writes:
> >
> > ><(E-Mail Removed)> wrote in message
> > >news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Words and non-words, according to Microsoft et al Steve B NZ Computing 11 03-21-2008 11:52 PM
Replace stop words (remove words from a string) BerlinBrown Python 6 01-17-2008 02:37 PM
Words Words utab C++ 6 02-16-2006 07:00 PM
Non-noise words are incorrectly recognised as noise words. Peter Strĝiman ASP .Net 1 08-23-2005 01:26 PM
Re: A little bit of help regarding my linked list program required. - "words.c" - "words.c" Richard Heathfield C Programming 7 10-05-2003 02:38 PM



Advertisments