Giving Change: A Rudimentary Program (Questions)

Quote:

Exercise P2.9. *Giving Change.* Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Compute the difference, and compute the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return.

First, transform the difference into an integer balance, denominated in pennies. Then compute the whole dollar amount. Subtract it from the balance. Compute the number of quarters needed. Repeat for dimes and nickels. Display the remaining pennies.

Here's what I have so far:

Code:

`/*----------------------------------------------------`

Exercise P2.9

-----------------------------------------------------*/

import ccj.*;

public class Change

{

public static void main(String[] args)

{

System.out.println("Amount Due in Dollars?");

double amountd = Console.in.readDouble();

System.out.println("Amount Received in Dollars?");

double amountr = Console.in.readDouble();

double difference = (amountr - amountd);

//Convert to Pennies

int balance = difference * 100;

System.out.println("The difference is $" + difference + ".");

System.out.println("The difference is " + balance + " pennies.");

}

}

I'm stuck in the step where I calculate the change received. I've succesfully converted the balance to pennies, but I'm stuck on what to do next.

I'm thinking maybe that with the use of "if" statements, that I can succesfully give the amount of change necessary in dollars, quarters, dimes, nickels, and pennies.

But here's what I'm also thinking: there are several combinations of dollars, quarters, dimes, nickels, and pennies. Does it not matter what combination I use?

Thanks.