Answer:
Step-by-step explanation:
The following program was written in Java. It creates a representation of every coin and then asks the user for a number of cents. Finally, it goes dividing and calculating the remainder of the cents with every coin and saving those values into the local variables of the coins. Once that is all calculated it prints out the number of each coin that make up the cents.
import java.util.Scanner;
class changeCentsProgram {
// Initialize Value of Each Coin
final static int QUARTERS = 25;
final static int DIMES = 10;
final static int NICKELS = 5;
public static void main (String[] args) {
int cents, numQuarters,numDimes, numNickels, centsLeft;
// prompt the user for cents
Scanner in = new Scanner(System.in);
System.out.println("Enter total number of cents (positive integer): ");
cents = in.nextInt();
System.out.println();
// calculate total amount of quarter, dimes, nickels, and pennies in the change
centsLeft = cents;
numQuarters = cents/QUARTERS;
centsLeft = centsLeft % QUARTERS;
numDimes = centsLeft/DIMES;
centsLeft = centsLeft % DIMES;
numNickels = centsLeft/NICKELS;
centsLeft = centsLeft % NICKELS;
// display final amount of each coin.
System.out.print("For your total cents of " + cents);
System.out.println(" you have:");
System.out.println("Quarters: " + numQuarters);
System.out.println("Dimes: " + numDimes);
System.out.println("Nickels: " + numNickels);
System.out.println("Pennies: " + centsLeft);
System.out.println();
}
}