Ask Question

1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent number of pennies, nickels, dimes, and quarters. Acceptable values are those which when multiplied by 100 will be exactly divisible by 50 (100*value must be exactly divisible by 50). Write a caller main function to call your function.

+2
Answers (1)
  1. 22 March, 05:45
    0
    import java. util. Scanner;

    public class Main

    {

    public static void main (String[] args) {

    valueInDollars ();

    }

    public static void valueInDollars () {

    double currentMoney, quarters, dimes, nickels, pennies;

    Scanner input = new Scanner (System. in);

    System. out. print ("Enter a value in dollars: ");

    currentMoney = input. nextDouble ();

    currentMoney * = 100;

    quarters = (int) currentMoney / 25;

    currentMoney = currentMoney % 25;

    dimes = (int) currentMoney / 10;

    currentMoney = currentMoney % 10;

    nickels = (int) currentMoney / 5;

    currentMoney = currentMoney % 5;

    pennies = currentMoney;

    System. out. print ("Quarters: " + quarters + "/n" + "Dimes: " + dimes + "/n" + "Nickels: " + nickels + "/n" + "Pennies: " + pennies);

    }

    }

    Explanation:

    Inside the function:

    - Declare the variables

    - Ask the user for a value in dollars

    - Multiply that value by 100

    - Find the amount of quarters, dimes, nickels, and pennies

    - Print the values

    Inside the main:

    - Call the function
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent number of ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers