View Single Post
Old 12-19-2008, 10:52 PM   #7 (permalink)
Black.Ice.
Black.Ice.'s Avatar
 
Junior Techie

Join Date: Aug 2007

Location: Boston, MA

Posts: 54

Black.Ice. is on a distinguished road

Send a message via AIM to Black.Ice. Send a message via MSN to Black.Ice.
Default Re: Need Help with Program

Thanks all for the help. I got the program working a few days ago.

Code:
/**
 * This program takes a user input of money in cents and prints all the possible
 * representations of that amount as a combination of quarters, deimes, nickels, 
 * and pennies. It then displays the total number of possible configurations. 
 *
 */

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();            // User input of cents
    
    int counter = 0;   // declares the variable counter which keeps track of total configurations
   
    for(int quarters = 0; quarters <= cents / 25; quarters++)   // finds number of quarters
    {
      int centsAfterQuarters = cents - (quarters * 25);
            
      for(int dimes = 0; dimes <= centsAfterQuarters / 10; dimes++)     // finds number of dimes
      {
        int centsAfterDimes = centsAfterQuarters - (dimes * 10);
         
        for(int nickels = 0; nickels <= centsAfterDimes / 5; nickels ++)     // finds number of nickels
        {
          int centsAfterNickels = centsAfterDimes - (nickels * 5);            // remaining cents are the pennies         
          counter++;           //increments number of configurations after each iteration by 1
          
          System.out.println(cents + " cents = " + quarters + " quarters + " + dimes + " dimes + " + nickels + " nickels + " + centsAfterNickels + " pennies");                 
        }
      } 
    }
    System.out.println("There are " + counter + " possible ways to make " + cents + " cents using coins.");
  } 
}

__________________
$500 rig ftw:

Case: CM 690 Black ATX Mid Tower
Mobo ASUS M2N32-SLI Deluxe AM2 nForce 590 SLI
CPU: AMD Athlon 64 X2 6400+ Black Edition @ 3.2GHz 23 C idle 37 load :O
GFX: 8600 GT XXX 256 mb
RAM: Corsair XMS2 2GB DDR2 800 mhz PC2 6400
HDD: Seagate Barracuda ST3320620AS 320GB 7200 RPM w/ Slave Western Digital Caviar WD800BB 80GB 7200 RPM
HSF: Zalman CNPS9700 LED 110mm 2 Ball
PSU: CM eXtreme Power Dual 12V rails @ 36A 650W

Tee Hee!
Black.Ice. is offline