need to do the conversion as said above.

eg. "one thousand five hundred" --> 1500
1500-->"one thousand five hundred"

upto billion..

tried using this logic..

separate billion, million, thousnd, units..made std fn

fn_conv(){ convert to hundredth place.. then store to var.. million, billion ..}

then print in format.. ("%d,%d,%d,%d",billion,million,thousnd,units);

but getting weird outputs.. plzz somebody help me out..this is asessmnt 4 my job's training..

You can find code for this all over the place. Here is how I did it a while back in response to a similar question:

#include <stdio.h>
#include <string.h>

char *wordbuild ( char *n, int ncomm )
{
  int i, nleft, len;
  char *p = NULL;
  static char ret[1024];
  
  /* Word lists */
  static char *ones[] = {"one ","two ","three ","four ",
    "five ","six ","seven ","eight ","nine "};
  static char *tens[] = {"ten ","eleven ","twelve ","thirteen ",
    "fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
  static char *twenties[] = {"","twenty ","thirty ","forty ",
    "fifty ","sixty ","seventy ","eighty ","ninety "};
  static char *hundreds[] = {
    "hundred ","thousand ","million "};
  
  memset ( ret, '\0', 1024 );
  len = strlen ( n );
  
  for ( i = 0; i < len; i++ ) {
    if ( ( p = strchr ( ( n[i] == ',' ) ? &n[++i] : &n[i], ',' ) ) == NULL )
      p = &n[strlen ( n )];

    if ( n[i] == '0' )
      continue;
    
    if ( ( nleft = ( p - &n[i] ) ) != 0 ) {
      if ( nleft == 3 ) {
        strcat ( ret, ones[n[i] - '0' - 1] );
        strcat ( ret, hundreds[0] );
      }
      else if ( nleft == 2 ) {
        if ( n[i] == '1' ) {
          strcat ( ret, tens[n[++i] - '0'] );
          nleft--;
        }
        else
          strcat ( ret, twenties[n[i] - '0' - 1] );
      }
      else
        strcat ( ret, ones[n[i] - '0' - 1] );
    }
    
    if ( nleft == 1 && ncomm != 0 )
      strcat ( ret, hundreds[ncomm--] );
  }
  
  return ret;
}

char *commaize ( unsigned long n, int *ncomm )
{
  static char ret[30];
  
  int i = 0;
  char *p = &ret[sizeof(ret)-1];
  
  *p = '\0';
  *ncomm = 0;
  
  do {
    if ( i % 3 == 0 && i != 0 ) {
      *--p = ',';
      ++*ncomm;
    }
    
    *--p = (char)( '0' + n % 10 );
    
    n /= 10;
    
    i++;
  } while ( n != 0 );
  
  return p;
}

char *stow ( int n, char *buf )
{
  int i;
  char *p, *ret;
  
  p = commaize ( n, &i );
  ret = wordbuild ( p, i );
  
  if ( buf != NULL ) {
    strcpy ( buf, ret );
    return buf;
  }
  
  return ret;
}

int main ( void )
{
  char buf[1024];
  
  printf ( "%s\n", stow ( 123456789, NULL ) );
  printf ( "%s\n", stow ( 12, NULL ) );
  
  stow ( 23, buf );
  printf ( "%s\n", buf );
  
  return 0;
}

A similar conversion can be made for the inverse operation.

cud u guide me 4 the inverse. proc.??

believe me.. i searched...a LOT

>believe me.. i searched...a LOT
I believe you, but instead of searching, try thinking. The task isn't a difficult one, it's just a matter of figuring out exactly what you want to do and outlining the steps required to do it. Once you have the steps, you can put them into code in any language you want, but if you don't know the steps then no amount of mastery in C or C++ will help you solve the problem.

So what do you want to do? You want to take a number in word form, such as "one thousand five hundred", and turn it into the number form, 1500. Barring invalid input, all you need to do is notice that the relevant parts of the word form are the words that correspond to digits. So "one thousand five hundred" would become 15 when worked out. From there you're only a special case away from handling zero value digits. Because nothing comes after "hundred", you can place 00 at the end of the number and you have 1500. Modify that for the tens, hundreds, thousands and millions places and you're pretty much done.

well.. i did try 4 two days.. i'm kinda approaching the deadline... so just freaking out.
i got the logic right first.. took three alts.. chose the best..while putting it in coding, weird errors..thanx 4 the code. and 4 the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.