# Thread: just started c programming and i cant get my head around it :/

1. ## just started c programming and i cant get my head around it :/

ive been reading books tutorials etc... but i just cant get my head around how i would start or even structure the program i am so confused the program i am trying to make is as follows:

write a program that converts an amount of money specified into pennies into the old UK monetary units of pounds, shillings and pence. There are 12 pennies to the shilling, and 20 shillings to the pound. You will also need to make sure that only an integer number of pounds and shillings and pence are printed. So, if the input value is 241 (pennies) then your program should print out:

241 pennies is 1 pound, 0 shillings and 1 penny

or for 42 pennies:

42 pennies is 0 pounds, 3 shillings and 6 pence

so how would i go about understanding and coding a program like this? any help would really be apprecitaed thanks

2. Originally Posted by lilv101
so how would i go about understanding and coding a program like this? any help would really be apprecitaed thanks
Start at the beginning. The first thing you need is "an amount of money specified into [sic, I think you meant 'in'] pennies". Thus, the first thing you should do is decide where that is going to come from, write the code to get it, and check that it works properly.

3. oh yeah i forgot to mention we were given the pennies to work with:
11
13
42
100

4. Writing the actual code is one of the last steps in programming.

First, you must understand the problem. Just like solving word problems in algebra. It's very had to do the right thing and get the right answer if you don't even know what the problem is asking. Identify the important pieces of information. What are you given and what do you know? What are you asked to find? etc.

Next, you must derive a solution. This is not a program. This is a general "how do I solve the problem". You should be able to explain the process in clear English or whatever your native language is. If you can't explain the solution to another human in your native language, there's little chance you can tell a computer how to do it in a foreign language (C).

Then, once you understand the problem and have a solution, you begin coding. It's important to only code a little bit at a time and test regularly as you code. Write 5 or 10 lines, and test, write 5 or 10 more lines, test some more. It's much easier to find a problem in the last 10 lines you wrote than the last 200.

As for your LSD question, can you solve it by hand? How would you turn 42 pennies into pounds, shillings and pence? How many pennies make a shilling? How many pennies make a pound? How many shillings make a pound?

Work these out by hand. Pay attention to all the little steps you do, like "divide the number of pennies by 12 to get shillings". Those steps translate very closely to the code you will write.