# Troubles with a Change app

• 09-28-2011, 08:14 AM
kiLzeD
Troubles with a Change app
What it is suppose to do is determine the least number of bills/coins to give back in change starting with the highest with \$10 being the max

I can get it to work all the way to the \$1 bills, I can get quarters to sort of work (say I type in 47.63 as my input I get
Quote:

Enter number of DOLLARS and CENTS double : 47.63
Ten Dollar Bills: 4.0
Five Dollar Bills: 1.0
One Dollar Bills: 2.0
Quarters: 2.5200000000000102
as output)

Code:

```import java.util.Scanner; public class Project2 {   public static void main(String[] args)   {     double iTen = 0;     double iCash;     double iTens, TEN;     double iFives, FIVE;     double iOnes, ONE;     double iQuarters, QUARTER;     double iDimes, DIME;     double iNickles, NICKLE;     double iPennies, PENNY;     double iCents;     Scanner scan = new Scanner(System.in);     Scanner myScanner = new Scanner(System.in);     double value = 0;     System.out.print("Enter number of DOLLARS and CENTS double : ");     iCash = scan.nextDouble();     TEN = (int) iCash / 10;     FIVE = (int) (iCash / 5) - ((TEN / 5) * 10);     ONE = (int) iCash - (TEN * 10) - (FIVE * 5);     QUARTER = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1)) / .25;     DIME = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1) - (QUARTER * 4)) / .1;     NICKLE = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1)) / .25;     PENNY = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1)) / .25;     System.out.println("Ten Dollar Bills:  " + TEN);     System.out.println("Five Dollar Bills:  " + FIVE);     System.out.println("One Dollar Bills:  " + ONE);     System.out.println("Quarters:  " + QUARTER);     System.out.println("Dimes:  " + DIME);     System.out.println("Nickles:  " + NICKLE);     System.out.println("Pennies:  " + PENNY);   } }```
Anyone see what I am doing wrong or if I am doing something a longer way some shortcuts (I am assuming there is a more efficient way to calculate it)

EDIT: Yes I know that from Quarters on it is not right, that is where I am stuck ex.
Code:

```    QUARTER = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1)) / .25;     DIME = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1) - (QUARTER * 4)) / .1;     NICKLE = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1)) / .25;     PENNY = (iCash - (TEN * 10) - (FIVE * 5) - (ONE * 1)) / .25```
-kiLzeD
• 09-28-2011, 12:52 PM
JosAH
Re: Troubles with a Change app
Don't dimension the amount of money in dollars, use cents instead; that way you only have to use ints (there are no fractions of a cent).

kind regards,

Jos
• 09-28-2011, 11:29 PM
kiLzeD
Re: Troubles with a Change app
Thanks that worked (Sort of) I was able to get it to work for all but nickles for some reason.