Hi,
I'm doing the first chapter exercises on my Java book and I have been stuck for a problem for a while now. I'll print the question,
prompt/read a double value representing a monetary amount. Then determine the fewest number of each bill and coin needed to represent that amount, starting with the highest (assume that a ten dollar bill is the maximum size needed). For example, if the value entered is 47,63 (forty-seven dollars and sixty-three cents), and the program should print the equivalent amount as:
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickels
3 pennies"
etc.
I'm doing an example exactly as they said in order to get an idea, as you will see in the code. Nevertheless, I managed to print 4 dollars, and I can't figure out how to get "1 five dollar", only 7 dollars (see code).
Please, don't do the whole code for me. I just need some advice in regards to what I said. Thank you.
import java.util.Scanner;
public class PP29 {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
int amount;
double value;
double test1;
double quarter;
System.out.println("Enter \"double\" value: ");
value = sc.nextDouble();
amount = (int) value / 10; // 47,63 / 10 = 4.
int amount2 = (int) value % 10; // 47 - 40 = 7
quarter = value * 100; // 47,63 * 100 = 4736
int sum = (int) quarter % 100; // 4763 / 100 => 4763-4700 = 63.
System.out.println(amount);
System.out.println(amount2);
}
}