# Coin counting program in c

• 11-08-2012
vag3621
Coin counting program in c
:confused:
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 ?
• 11-08-2012
rags_to_riches
Yes, but then you wouldn't learn a damn thing.

Announcements - General Programming Boards
• 11-08-2012
Salem
> Can anyone tell me how can I create a program in C
Yes, you start small, compile often, keep testing as you go.
http://cboard.cprogramming.com/c-pro...t-process.html
• 11-08-2012
Quote:

Originally Posted by vag3621
:confused:
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.