Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double amount = 27.65;
- int num20, num10, num5, num2, num1, num50c, num20c, num10c = 0;
- do {
- if (amount - 20 >= 0) { //check to see that you can subtract the denomination
- //shorthand for subtracts 20 from amount and assigns it to amount, same as using amount = amount - 20;
- amount -= 20;
- num20++; //Increments num20 by 1;
- } else { //If you can't subtract, then leave the loop.
- break; //breaks out of the do-while loop;
- }
- } while (1==1); //keeps the loop running (because 1 always equals 1) - hint there's a better way of doing it.
- do {
- if (amount - 10 >= 0) { //check to see that you can subtract the denomination
- //shorthand for subtracts 10 from amount and assigns it to amount, same as using amount = amount - 10;
- amount -= 10;
- num10++; //Increments num10 by 1;
- } else { //If you can't subtract, then leave the loop.
- break; //breaks out of the do-while loop;
- }
- } while (1==1); //keeps the loop running (because 1 always equals 1) - hint there's a better way of doing it.
- System.out.println("$20: " + num20 + etc,etc,etc)
Add Comment
Please, Sign In to add comment