I know this is very simple for most, I am having a few issues understanding the coding. Pretty sure I am close to understanding but just can't make it there, especially with lack of sleep. Any help is greatly appreciated, I plan on sticking to these forums and learning as much as I can. I'm a computer science major also so it's very serious to me.
I have started writing this Java program for homework in Netbeans 8.0 IDE. The project is as; "This program reads a monetary amount in cents and prints the smallest possible number of coins equaling the amount." I am trying to use 289 as a test in cents. It should be 2 Dollar Coins, 3 Quarters, 1 Dimes and 4 Pennies for a total of 10 coins. My program is giving me 13 coins and I am unsure how to get it to appear which ones. I've pondered on this and read online tutorials but it's not clicking in my head, sadly. I hope this is normal I am getting worried. Been changing the code around alot, also it has to be 'monetary'.
import java.util.Scanner; public class Hw1 { public static void main(String [] args) { Scanner in = new Scanner(System.in); int cents; //input variables int dollars, quarters, dimes, nickels, pennies; //output System.out.print("Enter an amount in cents:"); amounts = in.nextInt(); dollars = amounts/100; amounts = amounts%100; quarters = dollars/25; dollars = dollars%25; dimes = quarters/10; quarters = quarters%10; nickels = dimes/5; dimes = dimes%5; pennies = nickels/1; nickels = nickels%1; System.out.println("("+dollars+" Dollars, "+quarters+" Quarters, "+dimes+" Dimes, "+nickels+" Nickels, "+pennies+" Pennies )"); } }