# Coin counting program in c

This is a discussion on Coin counting program in c within the C Programming forums, part of the General Programming Boards category; Can anyone tell me how can I create a program in C, that you will write an amount ;i.e. 1.72 ...

1. ## 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. Yes, but then you wouldn't learn a damn thing.

Announcements - General Programming Boards

3. > 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

4. Originally Posted by vag3621

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.