Analysis of the least number of coins/bills needed

How can i analise the least number of coins/bills??

Page 1 of 1

8 Replies - 8131 Views - Last Post: 08 January 2010 - 10:58 AM Rate Topic: -----

#1 Akilles   User is offline

  • New D.I.C Head

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

Analysis of the least number of coins/bills needed

Post icon  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   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 Akilles   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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... :(
Was This Post Helpful? 0
  • +
  • -

#4 NoobKnight   User is offline

  • D.I.C Head

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

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

Posted 08 January 2010 - 09:27 AM

View PostAkilles, 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.
Was This Post Helpful? 0
  • +
  • -

#5 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 Akilles   User is offline

  • New D.I.C Head

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

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

Posted 08 January 2010 - 10:39 AM

View PostNoobKnight, on 8 Jan, 2010 - 08:27 AM, said:

View PostAkilles, 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????
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#8 Akilles   User is offline

  • New D.I.C Head

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

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

Posted 08 January 2010 - 10:47 AM

View PostDogstopper, 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); 

Was This Post Helpful? 0
  • +
  • -

#9 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1