Analysis of the least number of coins/bills needed

Page 1 of 1

8 Replies - 8183 Views - Last Post: 08 January 2010 - 10:58 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=148806&amp;s=5913431501a91871deaccdbcf1c66ee0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Akilles

Reputation: 0
• Posts: 24
• Joined: 07-January 10

Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 05:15 AM

If for example i give 8,589 how can i analise this into bills and coins???

``` if money>0,01
money=money-0,01
```

i did this but it only reduse the money by 0,01....
i can't figure it out....

I'm new in java so please forgive me if it's a little bit obvious the answer for you...

Is This A Good Question/Topic? 0

Replies To: Analysis of the least number of coins/bills needed

#2 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 06:19 AM

can you please elaborate more. the question is very vague

#3 Akilles

Reputation: 0
• Posts: 24
• Joined: 07-January 10

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 06:31 AM

I want to make a programm that takes a number(as a amoun of money) and then show the analysis of the least number of coins and bills needed...From 500\$ to 0.01\$...

i tried to make it look like this with the code above but it is not correct...i only manage to reduse the amoun of money by 0.01 each time...

#4 NoobKnight

Reputation: 49
• Posts: 238
• Joined: 14-July 09

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 09:27 AM

Akilles, on 8 Jan, 2010 - 07:15 AM, said:

If for example i give 8,589 how can i analise this into bills and coins???

You need to start with the highest denomination first. Say, a 1,000.00 dollar bill
then a 100 dollar bill
then 50
then 20
then 10
then 5
then 1
then 50 cents
quarter
dime
nickle
penny.

So you would have 8 \$1000.00 bills (if greater than 1000 subtract and increment a counter)
when that fails do a test for \$100.00 bill, etc.

do all amounts until you get to zero dollars and cents.

#5 Dogstopper

Reputation: 2965
• Posts: 11,222
• Joined: 15-July 08

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 09:36 AM

If you look through my contributions, you will find a change returner in Java. You would need to make it where it accepts up to \$500 though, because my snippet doesn't go that high, but it gives you the simple algorithm to do this.

#6 Akilles

Reputation: 0
• Posts: 24
• Joined: 07-January 10

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 10:39 AM

NoobKnight, on 8 Jan, 2010 - 08:27 AM, said:

Akilles, on 8 Jan, 2010 - 07:15 AM, said:

If for example i give 8,589 how can i analise this into bills and coins???

You need to start with the highest denomination first. Say, a 1,000.00 dollar bill
then a 100 dollar bill
then 50
then 20
then 10
then 5
then 1
then 50 cents
quarter
dime
nickle
penny.

do all amounts until you get to zero dollars and cents.

yes but with what code????
I tryied to do it with the while...but it wasn't correct...

I want : if i give for example 8005\$ to show that there is 800 dollar bills and 50 cents...

I did it with the If too but again nothing...what do i do wrong????

#7 Dogstopper

Reputation: 2965
• Posts: 11,222
• Joined: 15-July 08

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 10:41 AM

We don't know without seeing your updated code.

#8 Akilles

Reputation: 0
• Posts: 24
• Joined: 07-January 10

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 10:47 AM

Dogstopper, on 8 Jan, 2010 - 09:41 AM, said:

We don't know without seeing your updated code.

```import javax.swing.JOptionPane;

/**
*
* @author AkilleS
*/
public class Main {
public static void main(String[] args) {
// TODO code application logic here
String money1; int money,D1,D2,D3,D4,D5,Apot;
money1 =JOptionPane.showInputDialog ("give amount of money");
money = Integer.parseInt (money1);
while (money >500){
money=money/2;
JOptionPane.showMessageDialog (null,"the analysis of your money is:"+money);
}

System.exit(0);

}

}

```

I am stuck here.....

```while (money >500){
money=money/2;
JOptionPane.showMessageDialog (null,"the analysis of your money is:"+money);
```

#9 erik.price

• D.I.C Lover

Reputation: 486
• Posts: 2,690
• Joined: 18-December 08

Re: Analysis of the least number of coins/bills needed

Posted 08 January 2010 - 10:58 AM

Why do you divide money by 2 every time?

One method is to use a combination of modulus and division to find the change.

Here's a link to dogstopper's snippet, you should look at it and see if you can piece together your own from it http://www.dreaminco...snippet4742.htm

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }