Created
January 13, 2014 00:00
-
-
Save cangevine/8392457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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