Help PLease

Ok i have an assigment in my computer science 104 class in college it goes as follows:

Write a program that reads in a number supplied by the user and prints out that number in words. For example, if I were to type in:
125
The program should respond with:
one hundred twenty-five
Be careful to test this program so that it works with all numbers in the range 0 to 9999.

I need this to work with while loops and if statements only if possible, anything will help just a way i could start off trying to learn this. Thanks anyone,

Ryan Perrott

Comments

  • : Ok i have an assigment in my computer science 104 class in college it goes as follows:
    :
    : Write a program that reads in a number supplied by the user and prints out that number in words. For example, if I were to type in:
    : 125
    : The program should respond with:
    : one hundred twenty-five
    : Be careful to test this program so that it works with all numbers in the range 0 to 9999.
    :
    : I need this to work with while loops and if statements only if possible, anything will help just a way i could start off trying to learn this. Thanks anyone,
    :
    : Ryan Perrott
    :
    :

    steps that would help you with this assigment .
    1. perform a loop that each pass will cut the right number and put 0
    instead . for example . first pass will cause the next situation

    Num = 123 ' <- before pass

    LastNum = 3 ' <- after pass
    Num = 120 '

    2. now what you have to do is to check the last num with if statments
    (switch case is better if you can) .

    3. concate with strcat the new string (but remember to concate
    from right to left)

    4. go to step 1 if Num > 0

    this is the whole program lot of code writing but not to complicate
    if furture assiste will need just post the problem

  • [b][red]This message was edited by blindleaf at 2002-10-29 10:2:13[/red][/b][hr]
    [b][red]This message was edited by blindleaf at 2002-10-29 9:57:32[/red][/b][hr]
    ok how should i make the actual words in the program, i dont know how to use strings in C whats the syntax and such for strings in C? Also with the loop that takes off the last number and replaces with a 0 could you give me an example of code for that?





  • : [b][red]This message was edited by blindleaf at 2002-10-29 10:2:13[/red][/b][hr]
    : [b][red]This message was edited by blindleaf at 2002-10-29 9:57:32[/red][/b][hr]
    : ok how should i make the actual words in the program, i dont know how to use strings in C whats the syntax and such for strings in C? Also with the loop that takes off the last number and replaces with a 0 could you give me an example of code for that?
    :
    :
    :
    : [/code]
    : #include
    #include
    #include


    void main()
    {
    int Cntr=0;
    int i;
    short DNum[10]; // number
    int Multi=10;
    unsigned long SrcNum;

    char Buff[256];
    char Buff1[256];

    printf("Enter Number :>");

    scanf("%ul",&SrcNum);

    printf("
    ");
    // This Code parse number
    while (SrcNum>0)
    {
    DNum[Cntr]=(SrcNum%Multi); // Take out last number


    SrcNum -=DNum[Cntr];

    Multi *=10;
    Cntr++;

    }


    for (i=0;i %s Buff1 ->%s
    ",Buff,Buff1);


    }
    [/code]
    :



  • hey um. thats cool i think i figured it out that way , would there be a way to do it without strings, and with just if and while statements? if so could you give me an example, cause we've only gone over those and i think the prof might want me using them instead of something we haven't gone over yet. thanks
  • [b][red]This message was edited by ploto at 2002-10-31 3:50:19[/red][/b][hr]
    : hey um. thats cool i think i figured it out that way , would there be a way to do it without strings, and with just if and while statements? if so could you give me an example, cause we've only gone over those and i think the prof might want me using them instead of something we haven't gone over yet. thanks
    :

    There are 2 ways.

    1. first of all figure out how long is your number.
    save the length (for example 1000 is 4)

    2. parse the number for left to right and not form right to left
    as in the example. (you can do it because you know how many digits
    you have ) save the left digit

    3. now u know which digit is it for example (2000 will have the
    following values DigitPosition = 4 DigitValue=2)

    4. with if statement print as follow

    [code]
    ...
    if (DigVal==0)
    {
    ...
    }
    ....
    if (DigVal==4)
    {
    printf("four");

    if (DigPos==2)
    printf("ty ");
    if (DigPos==3)
    printf(" hundred ");
    if (DigPos==4)
    printf(" thousand ");
    }
    ...

    if (DigVal==9)
    {
    ...
    }



    [/code]

    put a spacail attention on 10-12 which have diffrent syntax

    The other way is 2 have if for each number 1-19,20-90,100-900,1000-
    9000 .
    it is more code to write but it is less brain work.




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories