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 ?
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 ?
Yes, but then you wouldn't learn a damn thing.
Announcements - General Programming Boards
> 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.
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.