The program is supposed to output the following:
Please Enter the Cost of the Item: 4.57 Please Enter the Amount Paid: 5.00 Change Owed: 0.43 Quarters: 1 Dimes: 1 Nickels: 1 Pennies: 3
Instead, I keep getting:
Please Enter the Cost of the Item: 4.57 Please Enter the Amount Paid: 5.00 Change Owed: 0.43 Quarters: 0 Dimes: 0 Nickles: 1 Pennies: 0
Here is the code I'm using. Please help, thank you!!!
import java.util.Scanner; public class change { public static void main (String [] args){ System.out.println("Please Enter the Cost of the Item: "); Scanner scan = new Scanner(System.in); double cost = scan.nextDouble(); System.out.println("Please Enter the Amount Paid: "); double paid = scan.nextDouble(); double owed = (paid - cost); double owed_final = (double)Math.round(owed * 1000) /1000; int quarters = (int)(paid / 25); int dimes = (int)((paid % 25) / 10); int nickels = (int)((paid % 25 % 10) / 5); int pennies = (int) (paid % 25 % 10 % 5); System.out.println("Change Owed: " + owed_final); System.out.println("Quarters: " + quarters); System.out.println("Dimes: " + dimes); System.out.println("Nickles: " + nickels); System.out.println("Pennies: " + pennies); } }