Discussion in 'C' started by Eulcid, Jul 11, 2010.

1. ### EulcidNew Member

Joined:
Jul 11, 2010
Messages:
4
0
Trophy Points:
0

i need to make a program that will convert the numbers to words.. Using C.Programming.

thanks..:smug:

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Not a difficult assignment. Gets tricky if you want to put and's in the correct place (need some lookahead code). Start simple; handling 1-19 should be very easy. Then handle 20-29 (small code extension). Then 30-39 and 40-99 should follow easily from this extension.

Then work on 100-199 and you can skip the and's for now, just do 100->"one hundred", 149->"one hundred forty-nine" for now and worry about "and" afterwards. After you've done this, as before 200-999 should follow easily.

You can see how this is going. Next work on 1000, then 10,000, then 100,000, then a million. You might be able to reuse code, for example 149 is one hundred and forty-nine, but 149,000 is one hundred and forty-nine thousand.

3. ### EulcidNew Member

Joined:
Jul 11, 2010
Messages:
4
0
Trophy Points:
0
Thanks Sir for responding to my problem..

But can you give me the example or the exact code for doing the 1-19? Because I really dont know how i am gonna start on this activity ..

Joined:
Jul 12, 2004
Messages:
15,296
366
Trophy Points:
83
Eulcid, do not expect someone would do your assignment and we can help to the extent we should and not to the extent we can.

5. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Then you're way out of your depth and need to consider whether you should be on this course. Here's a very small start but I doubt you have the ability to continue.
Code:
```case 1:
printf("One.");
break;
```

6. ### EulcidNew Member

Joined:
Jul 11, 2010
Messages:
4
0
Trophy Points:
0
waaaaaaaaaa i know that sir.. but my Professor said,its up to 9,999 do you mean i gonna make until case 1 to case 9999? (

7. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,012
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Don't be such a crybaby. Well, you could. That's one solution. But there is a better one. Have a close look at the numbers 20 to 29. What do you notice about them? That's right: they all start with "twenty". So if a number is between 20 and 20, you can display "twenty", then subtract 20, leaving you with a number from "one" to "nine".

Don't try to do this all at once. This is a common beginner mistake and no professional programmer writes a complete program in one go. Start with something small, i.e. 1-19, as I already said, then you can add to it. 20-29 will need some new code, but that same code can be reused, with a slight change, for 30-39 (print "thirty" then something between "one" and "nine"), 40-49 and so on up to 99. Then add code for 100, and you'll see you can reuse some of the existing stuff, for example 129, you print "one hundred", then you can reuse the same bit of code that printed 29, which itself reuses a bit of code that printed 1-19.

But I've said all this already. Start simple, and build on it. All complex programs can be broken down to a simple start plus a series of manageable changes, and that's certainly how I always write code.

8. ### EulcidNew Member

Joined:
Jul 11, 2010
Messages:
4
0
Trophy Points:
0
thanks about the info sir.. it helps a lot sir..

ill try to make what youve said,but please guide me if there is any wrong about my code..

thanks!

Joined:
Aug 6, 2004
Messages:
3,012