number to word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saiied
    New Member
    • Apr 2010
    • 1

    number to word

    hi i am trying to convert number between 0 -----10,000 .
    how can i write a code that i wil put any number and give me text. for exm:

    cin>> 9552
    automatically display
    nine thousand five hundred fifty two

    please help. thanks
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    The first step is to extract each base-10 digit, starting with the most-significant. How would you approach that?

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      if(N%10==1)cout <<"one";
      else if(N%10==2)cout <<"two";... and then go on from there.

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        if(N%10==1 unless it's actually 'eleven' ) cout<<"one";

        Comment

        • Dheeraj Joshi
          Recognized Expert Top Contributor
          • Jul 2009
          • 1129

          #5
          cin>> 9552
          automatically display
          nine thousand five hundred fifty two
          if number is 95524

          How you want it to display?
          ninety five thousand five hundred and twenty four

          or

          nine five five two four

          This holds good if the number entered is above 50 lack or say 100 crore.

          Regards
          Dheeraj Joshi

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Scope of requirements questions:
            1. Do you have to handle negative numbers?
            2. What is the maximum number of decimal digits you have to support?
            3. Do you have to support decimal fractions?

            There are culture-specific variations, but the way I was taught to read numbers aloud is exemplified below:
            224,224,224,224 =
            two hundred twenty four billion,
            two hundred twenty four million,
            two hundred twenty four thousand,
            two hundred twenty four

            The same decoding algorithm is used for each triad. You should take advantage of that regularity.

            Except for the special case when N==0, your number decoder function has to do the following for each nonzero triad:
            > call the triad decoder
            > append the suffix appropriate for that triad.

            Your triad decode function can decode each decimal digit independently except when the two least significant digits are between 10 and 19.

            Comment

            • whodgson
              Contributor
              • Jan 2007
              • 542

              #7
              yes newb16 completely missed that but donbrock got it in his last line.

              Comment

              Working...