Assignment: get integers and display in words

Discussion in 'C Programming' started by aatish19@gmail.com, Apr 12, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Re: Assignment: get integers and display in words

    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
     
    Robert Gamble, Apr 12, 2006
    #2
    1. Advertising

  3. <> wrote in message
    news:...
    > 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
     
    Fred Kleinschmidt, Apr 12, 2006
    #3
  4. Fred Kleinschmidt opined:

    >
    > <> wrote in message
    > news:...
    >> 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>
     
    Vladimir S. Oka, Apr 12, 2006
    #4
  5. <> wrote in message
    news:...
    > 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!
     
    stathis gotsis, Apr 12, 2006
    #5
  6. Re: Assignment: get integers and display in words

    "stathis gotsis" <> writes:

    ><> wrote in message
    >news:...
    >> 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.
     
    Chris McDonald, Apr 12, 2006
    #6
  7. Jaspreet Guest

    Re: Assignment: get integers and display in words

    Chris McDonald wrote:
    > "stathis gotsis" <> writes:
    >
    > ><> wrote in message
    > >news:...
    > >> 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.
     
    Jaspreet, Apr 13, 2006
    #7
  8. santosh Guest

    Re: Assignment: get integers and display in words

    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.
     
    santosh, Apr 13, 2006
    #8
  9. santosh Guest

    Re: Assignment: get integers and display in words

    santosh wrote:
    > 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.
     
    santosh, Apr 13, 2006
    #9
  10. Re: Assignment: get integers and display in words

    "Jaspreet" <> wrote in message
    news:...
    >
    > Chris McDonald wrote:
    > > "stathis gotsis" <> writes:
    > >
    > > ><> wrote in message
    > > >news:...
    > > >> 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.
     
    stathis gotsis, Apr 13, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Strøiman
    Replies:
    1
    Views:
    2,132
    Peter Strøiman
    Aug 23, 2005
  2. Richard Heathfield
    Replies:
    7
    Views:
    393
    Barry Schwarz
    Oct 5, 2003
  3. utab

    Words Words

    utab, Feb 16, 2006, in forum: C++
    Replies:
    6
    Views:
    445
    Daniel T.
    Feb 16, 2006
  4. BerlinBrown
    Replies:
    6
    Views:
    4,832
  5. Lasse Edsvik

    replace words with bold words

    Lasse Edsvik, Oct 5, 2003, in forum: ASP General
    Replies:
    9
    Views:
    252
Loading...

Share This Page