Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package changeprogram;
- /**
- *
- * @author scougan0631
- */
- import java.util.Scanner;
- public class Main {
- /**
- * This program will take any amount of money (less than a dollar) and give
- * the user the minimum amount of each coin they need
- */
- public static void main(String[] args) {
- Scanner scan = new Scanner (System.in);
- double cost;
- int quarter = 0;
- int dime = 0;
- int nickel = 0;
- int penny = 0;
- System.out.println("Enter the amount of change.");
- cost = scan.nextDouble ();
- while (cost >= 0.25) {
- cost = cost - 0.25;
- quarter++;
- }
- while (cost >= 0.10) {
- cost = cost - 0.10;
- dime++;
- }
- while (cost >= 0.05) {
- cost = cost - 0.05;
- nickel++;
- }
- while (cost == 0.01) {
- cost = cost - 0.01;
- penny++;
- }
- System.out.println ("quarters =" + quarter);
- System.out.println ("dime =" + dime);
- System.out.println ("nickel =" + nickel);
- System.out.println ("penny =" + penny);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement