Hi! I have to create a program where the user enters a certain amount of money and the program will tell them how many of each bill (5, 10, 20, 100) and coins (loonie, toonie, nickles, dimes, quarters) the amount they entered consists of, USING THE LEAST AMOUNT OF BILLS AND COINS. I have created a code already but for some reason it wont output the correct numbers!
I am a beginner and need a bit of guidance and need to know why my code isnt working.
Thanks for the help!
import java.io.*; public class ReviewProblem1 { public static void main (String [] args) throws IOException { BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));//BufferedReader reads input double c = 0; double f = 0; double i = 0; double l = 0; double o = 0; double r = 0; double u = 0; double x = 0; double intc = 0; System.out.println("Please enter your input amount:");//asks user to enter input amount String input = myInput.readLine();//assigns users input to inputA double amount = Double.parseDouble (input);//converts inputA into double if (amount == 100) { System.out.println ("1 100 dollar bill"); } if (amount < 100) { if (amount < 100 && amount >= 50) { double inta = amount / 50; double intb = Math.floor(inta); System.out.println (intb + " 50 dollar bills"); intc = amount - 50; } else if (intc >= 20 && intc < 50) { double a = intc / 20; double b = Math.floor(a); System.out.println ( b + " 20 dollar bills"); c = intc - (b*20); } else if (c >= 10 && c <20) { double d = c / 10; double e = Math.floor(d); System.out.println (e + " 10 dollar bills"); f = c - (e*10); } else if (f >= 5 && f < 10) { double g = f / 5; double h = Math.floor(g); System.out.println (h + " 5 dollar bills"); i = f - (h*5); } else if (i >= 2 && i<5) { double j = i / 2; double k = Math.floor(j); System.out.println (k + " toonies"); l = i - (k*2); } else if (l >= 1 && l< 2) { double m = l / 1; double n = Math.floor(m); System.out.println (n + " loonies"); o = l - (n*1); } else if (o >= 0.25 && o < 1) { double p = o / 0.25; double q = Math.floor(p); System.out.println (q + " quarters"); r = o - (q*0.25); } else if (r >= 0.10 && r < 0.25) { double s = r / 0.10; double t = Math.floor(s); System.out.println (t + " dimes"); u = r - (t*0.10); } else if (u >= 0.05 && u < 0.10); { double v = u / 0.05; double w = Math.floor(v); System.out.println ( w + " nickles"); x = u - (w*0.05); } if (x >= 0.01 && x < 0.05) { double y = x / 0.01; double z = Math.floor(y); System.out.println (z + " pennies"); } } } }