Skip to content

Instantly share code, notes, and snippets.

@cangevine
Created January 13, 2014 00:00
Show Gist options
  • Save cangevine/8392457 to your computer and use it in GitHub Desktop.
Save cangevine/8392457 to your computer and use it in GitHub Desktop.
public class Register {
public static void main(String[] args) {
System.out.println("Welcome to the cash register!");
double cost = 9.76;
double totalPaid = 20.00;
double change = totalPaid - cost;
int dollars = (int) Math.floor(change);
int coins = (int) ((change - dollars) * 100);
int quarters = coins / 25;
coins = coins - (quarters * 25);
int dimes = coins / 10;
coins = coins - (dimes * 10);
int nickels = coins / 5;
coins = coins - (nickels * 5);
int pennies = coins;
System.out.println("Your change is..."+dollars+" dollars, "+quarters+" quarters, "+dimes+" dimes, "+nickels+" nickels, and "+pennies+" cents");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment