hey guys below is my code for a change finder the code takes in a sales total and the amount payed and gives a change value and the amount of coins without using nickles. i cant seem to figure out however why the code is one cent short on
Given $36.0 for a purchase of $32.27 we need
3 dollars 2 quarters 2 dimes 2 cents
it should be 3 cents not 2 it is right on my other tests however.
here is my code
import java.util.Scanner; public class Change { public static void main(String [] args) { double purchase; double pay; double change; int balance; int dollars; int quarters; int dimes; int cents; Scanner in = new Scanner(System.in); System.out.print("purchase"); purchase = in.nextDouble(); System.out.println("payment"); pay = in.nextDouble(); change = pay - purchase; balance = (int)(change * 100); System.out.println(balance); dollars = balance / 100; balance = (balance - (100 * dollars)); quarters = balance / 25; balance = (balance - (25 * quarters)); dimes = balance / 10; balance = (balance - (10 * dimes)); cents = balance / 1; balance = balance - (1 * cents); System.out.println("Given $" + pay + " for a purchase of $" + purchase + " we need"); System.out.println(dollars + " dollars " + quarters + " quarters " + dimes + " dimes " + cents + " cents"); } }
any help is appreciated i am stuck as to how to fix it. thanks i look forward to any suggestions.