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

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    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. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by lilv101 View Post
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    oh yeah i forgot to mention we were given the pennies to work with:
    11
    13
    42
    100

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting started with programming
    By Nathan in forum C++ Programming
    Replies: 21
    Last Post: 11-27-2006, 03:51 PM
  2. about getting started in C++ programming
    By Chidambar K in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2005, 07:04 PM
  3. Need help getting started in 802.11 programming
    By dcj1978 in forum Networking/Device Communication
    Replies: 4
    Last Post: 09-12-2003, 04:08 AM
  4. How did you get started in programming?
    By ZooTrigger1191 in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 07-18-2003, 12:26 PM
  5. Need Help Just Started Programming
    By bilbo_baggins17 in forum C++ Programming
    Replies: 2
    Last Post: 01-13-2002, 08:36 PM