My friend and I are trying to write a program to be able to count the lowest set of coins used to make x amount of money. I have this so far but we are lost now and don’t know why to go. I know you have to do something with money to make it a int and then say that makes wholemoney then you take wholemoney and divided by the quarter and find the rem but I dont know how to write the code for it. Any help would be appreciated.
import java.util.Scanner;
class Coins {
public static void main(String[] args) {
double money;
double dollars=1.00;
double quarters=0.25;
double dimes=0.10;
double nickels=0.05;
double pennies=0.01;
Scanner in=new Scanner(System.in);
System.out.println("Enter amount of given money():");
money=in.nextFloat();
}
}
You start by dividing the amount by the value of the most valuable coin. The integer part is the number of coins of the most valuable coin and the remaining amount is a remaining value that you divide by the next valuable coin. You do the same until there are either no more coins or the decimal part is zero.
Please note that the remaining amount here is the decimal part resulted from the division multiplied by the dividing coin value.