samedi 7 mars 2015

Displaying Change need information



I need to write a java program that computes what bills and change will be given for a sales transaction.


It can only dispense 20s, 10s, 5s, 1s, quarters, dimes, nickles, and pennies.


If it doesnt have to dispense a denomination (say your change is 50 cents, it should only dispense two quarters. It should make no mention of the other currency)


I can't get it to dispense the correct amount of currency, it just dispense all currencies (so for example, if it was $21 and I gave the cashier 22, the codes telling me to give .013 $20s, .294 $10s, ect.) If anyone can help me out that would be great.





double price; // declares how much the price is
double moneyGiven; // declares how much money the cashier is given
double change; // declares how much change is given in return

System.out.println("Enter the Price of the item:");
price = IO.readDouble()*100; {


{


System.out.println("Enter the Amount Given:");
moneyGiven = IO.readDouble()*100; {




if (moneyGiven > price); {


System.out.println("Your Change is:");

change = moneyGiven - price;
double twenties = change / 2000;
if (twenties >= 1); {
change = change % 2000;
System.out.println(twenties + "$20 Bills"); }

double tens = change / 1000;
if (tens >= 1); {
change = change % 1000;
System.out.println(tens + "$10 Bills"); }

double fives = change / 500;
if (fives >= 0); {
change = change % 500;
System.out.println(fives + "$5 Bills"); }

double ones = change / 100;
if (ones >= 0); {
change = change % 100;
System.out.println(ones + "$1 Bills"); }

double quarters = change / 25;
if (quarters >= 0); {
change = change % 25;
System.out.println(quarters + "Quarters"); }

double dimes = change / 10;
if (dimes >= 0); {
change = change % 10;
System.out.println(dimes + "Dimes"); }

double nickles = change / 5;
if (nickles >= 0); {
change = change % 5;
System.out.println(nickles + "Nickles"); }

double pennies = change / 1;
if (pennies >= 0); {
change = change % 1;
System.out.println(pennies + "Pennies"); }




if (moneyGiven <= price);
System.out.println("Not enough money given");

if (moneyGiven == price);
System.out.println("There is no Change to be given.");

}
}
}
}
}
}





Aucun commentaire:

Enregistrer un commentaire