1. Member Join Date
Dec 2008
Posts
4
Rep Power
0

## Make Change

Hello all. Im taking AP Comp Sci and I'm little stuck on one of the programs we were assigned.

The program basically takes a user input of cents and converts that into all possible combinations of quarters, dimes, nickels and pennies. It then prints out the total number of possible configurations.

For example:

Java Code:
```How Many Cents: 6
6 cents = 0 quarters + 0 dimes + 0 nickels + 6 pennies
6 cents = 0 quarters + 0 dimes + 1 nickel + 1 pennies
There are 2 possible ways to make 6 cents using coins.```
Here is what I have so far:

Java Code:
```import java.util.Scanner;

public class MakeChange
{

public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println ("How many cents? ");
int cents = input.nextInt();

int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;

while (cents > 0)

if (cents >= 25)
{
quarters++;
cents -= 25;
}

else if (cents >= 10)
{
dimes++;
cents -= 10;
}

else if (cents >= 5)
{
nickels++;
cents -= 5 * nickels;
}

else if (cents >= 1)
{
pennies++;
cents -= 1;
}

System.out.println(cents + " cents = " + quarters + " quarters + " + dimes + " dimes + " + nickels + " nickels + " + pennies + " pennies");
}
}```
However, I know this is wrong because it only prints out the combination with the least amount of coins. It is supposed to print ALL possible combinations. Can anyone help?

Also, Im supposed to be using nested loops for these.

Thanks Again.
Last edited by Black.Ice.; 12-18-2008 at 05:32 AM.  Reply With Quote

2. ## First of all, do you have any algorithm to find those all combination?  Reply With Quote

3. Member Join Date
Dec 2008
Posts
4
Rep Power
0

## No. That is my main problem right now....Finding all the possible combinations.  Reply With Quote

4. Member Join Date
Dec 2008
Posts
4
Rep Power
0

## I got it figured out. :P  Reply With Quote

5. ## Most probably you have to think about permutations. It's the easiest way to figure out the way of selections. Then try to convert them into steps.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•