Advertisement
Guest User

Jums

a guest
Oct 1st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package changeprogram;
  2.  
  3. /**
  4. *
  5. * @author scougan0631
  6. */
  7.  
  8. import java.util.Scanner;
  9.  
  10. public class Main {
  11.  
  12. /**
  13. * This program will take any amount of money (less than a dollar) and give
  14. * the user the minimum amount of each coin they need
  15. */
  16. public static void main(String[] args) {
  17.  
  18. Scanner scan = new Scanner (System.in);
  19.  
  20. double cost;
  21. int quarter = 0;
  22. int dime = 0;
  23. int nickel = 0;
  24. int penny = 0;
  25.  
  26. System.out.println("Enter the amount of change.");
  27. cost = scan.nextDouble ();
  28.  
  29. while (cost >= 0.25) {
  30. cost = cost - 0.25;
  31. quarter++;
  32. }
  33.  
  34. while (cost >= 0.10) {
  35. cost = cost - 0.10;
  36. dime++;
  37. }
  38.  
  39. while (cost >= 0.05) {
  40. cost = cost - 0.05;
  41. nickel++;
  42. }
  43.  
  44. while (cost == 0.01) {
  45. cost = cost - 0.01;
  46. penny++;
  47. }
  48.  
  49. System.out.println ("quarters =" + quarter);
  50. System.out.println ("dime =" + dime);
  51. System.out.println ("nickel =" + nickel);
  52. System.out.println ("penny =" + penny);
  53.  
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement