Results 1 to 3 of 3
  1. #1
    kiLzeD is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default 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
    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)

    Java 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.
    Java 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
    Thanks in advance
    -kiLzeD

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    kiLzeD is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default 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.

Similar Threads

  1. Clock Troubles
    By brycepower1 in forum New To Java
    Replies: 55
    Last Post: 05-12-2011, 12:33 PM
  2. Char troubles
    By diggdude in forum New To Java
    Replies: 2
    Last Post: 11-10-2009, 03:55 PM
  3. Integer troubles again...
    By Tb0h in forum New To Java
    Replies: 1
    Last Post: 09-20-2009, 02:32 AM
  4. JOptionPane Troubles
    By Tb0h in forum New To Java
    Replies: 4
    Last Post: 08-26-2009, 01:12 PM

Posting Permissions

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