Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sales {
- public static void main (String[] args) {
- System.out.println("What is the total sales charge");
- double tsales = IO.readDouble();
- System.out.println("How much is the customer giving");
- double paid = IO.readDouble();
- if (paid < tsales) {
- IO.reportBadInput();
- return;
- }
- int twenty = 0;
- int ten = 0;
- int five = 0;
- int one = 0;
- int quarter = 0;
- int dime = 0;
- int nickel = 0;
- int penny = 0;
- double owe = paid - tsales;
- if (owe > 20) {
- while (owe > 20) {
- twenty ++;
- owe = owe - 20;
- }
- System.out.println(twenty + " $20 bills");
- }
- if (owe > 10) {
- while (owe > 10) {
- ten ++;
- owe = owe - 10;
- }
- System.out.println(ten + " $10 bills");
- }
- if (owe > 5) {
- while (owe > 5) {
- five ++;
- owe = owe - 5;
- }
- System.out.println(five + " $5 bills");
- }
- if (owe > 1) {
- while (owe > 1) {
- one ++;
- owe = owe - 1;
- }
- System.out.println(one + " $1 bills");
- }
- if (owe > 0.25) {
- while (owe > 0.25) {
- quarter ++;
- owe = owe - 0.25;
- }
- System.out.println(quarter + " Quarters");
- }
- if (owe > 0.10) {
- while (owe > 0.10) {
- dime ++;
- owe = owe - 0.10;
- }
- System.out.println(dime + " Dimes");
- }
- if (owe > 0.05) {
- while (owe > 0.05) {
- nickel ++;
- owe = owe - 0.05;
- }
- System.out.println(nickel + " Nickels");
- }
- if (owe > 0.01) {
- while (owe > 0.01) {
- penny ++;
- owe = owe - 0.01;
- }
- System.out.println(penny + " Pennies");
- } else{
- System.out.println("No Bills");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement