Solution written in JAVA.
Comments have been added in the code to understand the code.
import java.util.Scanner;
public class ConvertToDollar {
public static void main(String[] args) {
int quarters; //variable to store quarter
int dimes; //variable to store dimes
int nickels; //variable to store nickels
double dollar; //variable to store total value in dollar
Scanner scanner = new Scanner(System.in); //to scan the input
System.out.println("Enter quarters: ");
quarters = scanner.nextInt(); //to read quarter
System.out.println("Enter dimes: ");
dimes = scanner.nextInt(); //to read dimes
System.out.println("Enter nickels: ");
nickels = scanner.nextInt(); //to read nickels
scanner.close(); //scanner has to be closed to avoid leak
//calculate cents by multiplying 25 to quarters, 10 to dimes and 5 to nickels
int cents = (25 * quarters) + (10 *dimes) + (5 * nickels);
dollar = cents / 100.0; //calculate dollar from cents
System.out.println("Total value in dollar: "+dollar);
}
}
Output
Get Answers For Free
Most questions answered within 1 hours.