i need help with the following code below....
Basically what the program should do is take and input from the user ("in dollars and cents; Eg: $1.04 or $6") round up the value (if necessary) and print out the relevant coin combination.
my program works well with some values but if i enter a value with a 5 Cents it doesn't print out the correct coin combination; and also I'm having problems with rounding the value.
I'm stuck.....
please help me
import java.util.Scanner; public class CoinCalculator { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double total; int twoDollars; int oneDollar; int fiftyCents; int twentyCents; int tenCents; int fiveCents; int totalCents; System.out.print("Please enter an Amount:$ "); total = scan.nextDouble(); totalCents = (int)total; totalCents = (int)(100 * total); twoDollars = (int)((total) / 2); oneDollar = (int) ((total - (twoDollars * 2)) / 1); fiftyCents = (int)((total - (twoDollars * 2) - (oneDollar * 1)) / .50); twentyCents = (int)((total - (twoDollars * 2) - (oneDollar * 1) - (fiftyCents * .50)) / .20); tenCents = (int)((total - (twoDollars * 2) - (oneDollar * 1) - (fiftyCents * .50) - (twentyCents * .20)) / .10); fiveCents =(int) ((total-(twoDollars * 2)-(oneDollar * 1)-(fiftyCents * .50) - (twentyCents * .20) - (tenCents * .10))/.05); System.out.println("Two Dollar(s): " + twoDollars); System.out.println("One Dollar(s): " + oneDollar); System.out.println("Fifty Cent(s): " + fiftyCents); System.out.println("Twenty Cent(s): " + twentyCents); System.out.println("Ten Cent(s): " + tenCents); System.out.println("Five Cent(s): " + fiveCents); } }