Input numbers output words problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • majestic
    New Member
    • Feb 2008
    • 7

    Input numbers output words problem

    Hello,i'm wondering if anyone can help me. The c program needs to input any number from 1-999 and it must output whatever number was input in words.i have made a start on the hundredths and tens...can anyone help me with wht i can use to input the data? When i compile and run the program,only if i put in a single digit then it prints (eg if i put in 5) five hundred, for 3 digit numbers it doesnt print anything.I think the problem is inputing the numers,can anyone help me with how to input the numbers?(what ways can i use?) Can You tell me if anything is wrong with what i already have also?thank you very much...
    here is the code
    Last edited by sicarie; Mar 8 '08, 05:20 AM. Reason: Posting Guidelines 'whole code responses'
  • majestic
    New Member
    • Feb 2008
    • 7

    #2
    i think the array should only have one number(i have 3 in the array above),its supposed to just be a 3 digit number..one number.can anyone help me with tht..thnx

    Comment

    • Parul Bagadia
      New Member
      • Mar 2008
      • 188

      #3
      Yaeh even i think so; you should have an array having only one number in it; abd have some variable so that u can access diff. places; as in units place tens place and so on......
      Because in case of three numbers; they themselves will have some places ; its not given that they all should be a single digit no.
      And anyhow you are converting a single no.

      Comment

      • majestic
        New Member
        • Feb 2008
        • 7

        #4
        yes,i know tht.but i tried using the array with one number in it..it still didnt work.i need to assign values(ones,ten s,hundredths) .i need to tell the computer tht in the case of 768,7 is a hundred,6 is a ten,and 8 is a one....can anyone plz tell how i can do tht.i've been reading and i cant find a way to do it.

        Comment

        • majestic
          New Member
          • Feb 2008
          • 7

          #5
          yes,i know tht.but i tried using the array with one number in it..it still didnt work.i need to assign values(ones,ten s,hundredths) .i need to tell the computer tht in the case of 768,7 is a hundred,6 is a ten,and 8 is a one....can anyone plz tell how i can do tht.i've been reading and i cant find a way to do it.thank you very much

          Comment

          • MACKTEK
            New Member
            • Mar 2008
            • 40

            #6
            I am thinking of a different method to do this.

            User inputs a number (in text).
            Convert to an Integer i (perhaps you can skip that if user enters integer directly)

            Then take int i and divide it by the maximum "place" value and cast it.
            For example
            hund=int(i/100);
            // this casts a division that would usually not be a whole number value into an integer... it does not round up, simply casts aside anything to the right of the decimal point.

            If you print hund it will be a single digit.

            for example if the user enters 955... int(955/100) will be 9.

            The next step is to subtract 9*100 from the total.

            Leaving you with 55.

            You would then repeat the cast (i/10) etc...

            that should help you to get the numbers you need.

            Converting it to text can be done with judicious use of if statements , case statement, maybe even enums combined.
            For example:
            You could declare an Enum that enumerates the text from "one hundred to nine hundred"

            You will have to take into account that normal English does not usually pronounce the hundreds, tens place etc if they do not exist.
            Also, as you already noticed, from 0 to 19 is a special case.

            Hope that helps.

            Comment

            • majestic
              New Member
              • Feb 2008
              • 7

              #7
              hey,thank you. i have to input the number rather than the text but i got the idea.i'll work wit it..thank you
              Originally posted by MACKTEK
              I am thinking of a different method to do this.

              User inputs a number (in text).
              Convert to an Integer i (perhaps you can skip that if user enters integer directly)

              Then take int i and divide it by the maximum "place" value and cast it.
              For example
              hund=int(i/100);
              // this casts a division that would usually not be a whole number value into an integer... it does not round up, simply casts aside anything to the right of the decimal point.

              If you print hund it will be a single digit.

              for example if the user enters 955... int(955/100) will be 9.

              The next step is to subtract 9*100 from the total.

              Leaving you with 55.

              You would then repeat the cast (i/10) etc...

              that should help you to get the numbers you need.

              Converting it to text can be done with judicious use of if statements , case statement, maybe even enums combined.
              For example:
              You could declare an Enum that enumerates the text from "one hundred to nine hundred"

              You will have to take into account that normal English does not usually pronounce the hundreds, tens place etc if they do not exist.
              Also, as you already noticed, from 0 to 19 is a special case.

              Hope that helps.

              Comment

              Working...