Thread: Coin counting program in c

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    5

    Coin counting program in c


    Can anyone tell me how can I create a program in C, that you will write an amount ;i.e. 1.72 $ and the program will give me as output the minimum of coins (pennies,nickels,dimes,quarters) needed ?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Yes, but then you wouldn't learn a damn thing.

    Announcements - General Programming Boards

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Can anyone tell me how can I create a program in C
    Yes, you start small, compile often, keep testing as you go.
    A development process
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by vag3621 View Post

    Can anyone tell me how can I create a program in C, that you will write an amount ;i.e. 1.72 $ and the program will give me as output the minimum of coins (pennies,nickels,dimes,quarters) needed ?
    We do a lot of things in everyday life, automatically. Making change is one of them. We would start by "counting up" probably:

    cost is 52 cents, you receive a dollar in payment, now make change:

    pennies: 1,2,3 "53,54,55"

    need to get to 75, so
    dime: 1 "65"

    need to get to 75, so
    dime: 1 "75"

    quarter is perfect, so
    quarter: 1 "1.00 dollar"

    All very OK and fits a human well, but that's not the easiest way to make change for a computer, certainly.

    Hint: for your program, start with changing all monies into pennies, (int allPennies maybe), right away. Then work downward from largest bills, to smallest, and then from the largest coin values to smallest coin values.

    (I'd save int pennies for the actual number of pennies in the change you're making).

    This approach works well because the computer is so good at arithmetic.

    Practice this approach by hand with paper and pen (and maybe a calculator) a few times, and you'll start to see the kind of logic that you need.
    Last edited by Adak; 11-08-2012 at 06:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Coin Counting Program Problems
    By kevinandrewsun in forum C Programming
    Replies: 3
    Last Post: 06-02-2012, 10:34 AM
  2. Coin Counting Program
    By woodyhavoc in forum C Programming
    Replies: 8
    Last Post: 03-14-2011, 02:15 AM
  3. Help coin program.
    By Kinto in forum C++ Programming
    Replies: 1
    Last Post: 09-12-2009, 08:00 PM
  4. Another Coin Counting Program
    By MipZhaP in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2005, 02:02 AM
  5. Coin counting (logic problem)
    By xlokix in forum C++ Programming
    Replies: 47
    Last Post: 01-20-2005, 03:22 PM