number to word conversion codes!

pls help me in doing my project! i have no idea on how to make this project! Example if i going to input 355 the out put should be three hundred fifty-five. The limit is up to ten million!! i badly needed the codes!!! Thank you!!!!!

Comments

  • : pls help me in doing my project! i have no idea on how to make this project! Example if i going to input 355 the out put should be three hundred fifty-five. The limit is up to ten million!! i badly needed the codes!!! Thank you!!!!!

    show us ur effort. nothing is better than whatever u try.
  • : : pls help me in doing my project! i have no idea on how to make this project! Example if i going to input 355 the out put should be three hundred fifty-five. The limit is up to ten million!! i badly needed the codes!!! Thank you!!!!!
    :
    : show us ur effort. nothing is better than whatever u try.
    :

    Try this code...
    It also validate negative numbers...

    #include
    #include
    #include

    #define MAXLEN 13
    #define NUM0 '0'
    #define NUM9 '9'
    #define DOT '.'
    #define NEG '-'

    #define true 1
    #define false 0

    void ones(int );
    void tens(int );
    void copy(char* , const char *, int , int );
    void display(char *);
    int check(char *);

    int main ()
    {
    char snum[MAXLEN];

    /* Collect and check */
    check(snum);

    /* Display output */
    display(snum);

    printf("

    ");

    return 0;
    }

    int check(char *pnum)
    {
    int ictr, ilen;
    short scdot;

    do
    {
    /* Ask the user input data */
    printf("Input number: ");
    fgets(pnum, MAXLEN, stdin);

    /* Make it a Null terminated string */
    ilen = strlen(pnum) - 1;
    *(pnum + ilen) = '';


    /* Check if all the char is valid */
    ictr = 0;
    scdot = false;
    while (ictr < ilen && ((*(pnum + ictr) >= NUM0 &&
    *(pnum + ictr) <= NUM9) ||*(pnum + ictr) == DOT ||
    *(pnum + ictr) == NEG))
    {
    if (ictr>0 && *(pnum + ictr) == NEG) break;
    if (*(pnum + ictr) == DOT)
    {
    if (scdot) break;
    scdot = true;
    }
    ictr++;
    }
    } while(ilen != ictr);

    return 1;
    }

    void ones(int inum)
    {
    /* Display a one digit */
    switch(inum)
    {
    case 1:
    printf("One ");
    break;
    case 2:
    printf("Two ");
    break;
    case 3:
    printf("Three ");
    break;
    case 4:
    printf("Four ");
    break;
    case 5:
    printf("Five ");
    break;
    case 6:
    printf("Six ");
    break;
    case 7:
    printf("Seven ");
    break;
    case 8:
    printf("Eight ");
    break;
    case 9:
    printf("Nine ");
    break;
    }
    }

    void tens(int inum)
    {
    /* Display two digit */
    if (inum < 10) ones(inum); /* 1 - 9 */
    else if (inum <20) /* 10 - 19 */
    {
    switch(inum)
    {
    case 10:
    printf("Ten ");
    break;
    case 11:
    printf("Eleven ");
    break;
    case 12:
    printf("Twelve ");
    break;
    case 13:
    printf("Thirteen ");
    break;
    case 14:
    printf("Forteen ");
    break;
    case 15:
    printf("Fifteen ");
    break;
    case 16:
    printf("Sixteen ");
    break;
    case 17:
    printf("Seventeen ");
    break;
    case 18:
    printf("Eighteen ");
    break;
    case 19:
    printf("Nineteen ");
    break;
    }
    }
    else /* 20 - 99 */
    {
    switch(inum/10)
    {
    case 2:
    printf("Twenty ");
    break;
    case 3:
    printf("Thirty ");
    break;
    case 4:
    printf("Forty ");
    break;
    case 5:
    printf("Fifty ");
    break;
    case 6:
    printf("Sixty ");
    break;
    case 7:
    printf("Seventy ");
    break;
    case 8:
    printf("Eighty ");
    break;
    case 9:
    printf("Ninety ");
    break;
    }
    ones(inum%10);
    }
    }

    void copy(char *pcopy, const char *pcopied, int start, int end)
    {
    /* Copy string 2 to string 1 with a range */
    while(start<=end)
    {
    *pcopy = *(pcopied + start);
    pcopy++;
    start++;
    }

    *pcopy = '';
    }

    void display(char *pnum)
    {
    char temp[3];
    int ctr, len;
    short sfzero = 1;

    /* If first char is equal to '-', display Negative */
    if (*pnum == NEG)
    {
    printf("Negative ");
    ctr = 1;
    }
    else ctr = 0;

    /* Find the length of string, at the beginning to a dot(.) */
    len = 0;
    while (*(pnum + len) != '' && *(pnum + len) != DOT ) len++;


    while(ctr<len)
    {
    /* Test if the position has a remainder of 2 */
    if ((len - ctr) % 3 == 2 && (*(pnum + ctr) != '0' ||
    *(pnum + ctr + 1) != '0'))
    {
    if (*(pnum + ctr) != '0')
    {
    copy(temp, pnum, ctr, ctr + 1);
    }
    else
    {
    copy(temp, pnum, ctr + 1, ctr + 1);
    }

    tens(atoi(temp));
    ctr+=2;
    if (len - ctr == 3) printf("Thousand ");
    else if (len - ctr == 6) printf("Million ");
    sfzero = 0;
    }
    else if (*(pnum + ctr) != '0')
    {
    copy(temp, pnum, ctr, ctr);
    ones(atoi(temp));
    if ((len - ctr) % 3 == 0) printf("Hundred ");
    ctr++;
    if (len - ctr == 3) printf("Thousand ");
    else if (len - ctr == 6) printf("Million ");
    sfzero = 0;
    }
    else
    {
    if ((len-ctr) % 3 == 2) ctr+=2;
    else ctr++;
    }
    }

    if (sfzero) printf("Zero ");


    /* Display fraction */
    if (len != strlen(pnum))
    {
    len ++;
    if (*(pnum + len) == '0' && *(pnum + len + 1) == '0')
    return;
    if (*(pnum + len) == '0' && *(pnum + len + 1) == '')
    return;

    printf("point ");
    if (*(pnum + len) != '0')
    {
    copy(temp, pnum, len, len + 1);
    tens(atoi(temp));
    }
    else
    {
    copy(temp, pnum, len + 1, len + 1);
    printf("Zero ");
    ones(atoi(temp));
    }
    }
    }
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