This is what I have so far but I have a rounding error when I use the amount 10.03:
Expand|Select|Wrap|Line Numbers
- public class Money
- {
- public static void main(String[] args)
- {
- double TOTAL_AMOUNT = 10.03;
- int money = (int)(TOTAL_AMOUNT * 100);
- System.out.println("Your money amount " + TOTAL_AMOUNT + " consists of");
- System.out.println("\t" + (money / 100) + " dollars");
- money = money % 100;
- System.out.println("\t" + (money / 25) + " quarters");
- money = money % 25;
- System.out.println("\t" + (money / 10) + " dimes");
- money = money % 10;
- System.out.println("\t" + (money / 5) + " nickels");
- money = money % 5;
- System.out.println("\t" + (money / 1) + " pennies");
- }
- }