Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Please Help Me about C Programming.. (http://www.go4expert.com/forums/help-c-programming-t22686/)

Eulcid 11Jul2010 11:30

Please Help Me about C Programming..
 
Please i need your help guys

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

please help me about the code.. my Professor said that we need to use Switch and For.

but i dont know how do i start... please help me.. :cryin:

thanks..:smug:

xpi0t0s 12Jul2010 16:05

Re: Please Help Me about C Programming..
 
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.

Eulcid 13Jul2010 10:35

Re: Please Help Me about C Programming..
 
Thanks Sir for responding to my problem..:D

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 :confused:..

shabbir 13Jul2010 12:38

Re: Please Help Me about C Programming..
 
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.

xpi0t0s 13Jul2010 13:37

Re: Please Help Me about C Programming..
 
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;


Eulcid 14Jul2010 12:09

Re: Please Help Me about C Programming..
 
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? :((

xpi0t0s 14Jul2010 14:22

Re: Please Help Me about C Programming..
 
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.

Eulcid 14Jul2010 17:29

Re: Please Help Me about C Programming..
 
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!

xpi0t0s 14Jul2010 17:46

Re: Please Help Me about C Programming..
 
Your code will only be wrong if it doesn't do the job. If it works then hand it in. If you get stuck, first try to solve it yourself, but if you're really stuck then post it and we'll have a look. It can help to try to explain what the code does to someone; this helps you work through it in your own mind.


All times are GMT +5.5. The time now is 09:13.