Write a solution to Programming Exercise 6-4.
SUGGESTION: Write a function that takes an amount of money expressed
as a floating-point number of dollars, and returns the number of ways
to make change for that amount using quarters, dimes, nickels and
pennies. You don't have to generate the actual combinations, just the
number of combinations.
WARNING: resist the temptation to write lots of code and then
start debugging. Particularly when you are working in an unfamiliar
language, it is critical to practice incremental development;
that is, you should start with a small, working program and gradually
add small additional features, testing as you go, until you have
a program that does what you want.
For example, when I wrote my solution to this homework,
I started with this:
#include <stdio.h>
#include <math.h>
/* the declaration of round is supposed to be in math.h,
but it's not, so you need the following to avoid an annoying
warning */
double round(double);
int print_change(double amount)
{
int cents = (int) round(amount * 100.0);
printf("%d\n", cents);
}
int main()
{
print_change(0.98);
}
Then I gradually added features until everything worked.
HINT: this is a classical problem. There are many solutions to it on
the Internet, so if you are stumped, feel free to Google around. But
if you go to an outside source, please acknowledge it on your
homework.