1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kondor19780726 [428]
3 years ago
14

Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per l

ine. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is:
Computers and Technology
1 answer:
Paraphin [41]3 years ago
6 0
I'm assuming Java, but if you need a different language, it shouldn't be too hard to transcribe.

public void toCoins(int totalChange) {
int[] coins = new int[5] //array of coin counts
int[] values = new int[]{100, 25, 10, 5, 1}
String[] singular = new String[]{"dollar", "quarter", "dime", "nickel", "penny"};
String[] plural = new String[]{"dollars", "quarters", "dimes", "nickels", "pennies"};
for(int i = 0; i < 5; I++) {
while(totalChange > values[i]) {
totalChange -= values[i];
coins[i]++;
}
}
for(int i = 0; i < 5; i++) {
if(coins[i] == 1) System.out.println("1 " + singular[i]);
else if(coins[i] > 1) System.out.println(coins[i] + " " + plural[I]);
}


You might be interested in
Write a program that prompts the user to enter positive integers (as many as the user enters) from standard input and prints out
julia-pushkina [17]

Answer:

Here is the JAVA program that prompts the user to enter positive integers from standard input and prints out the maximum and minimum values:

import java.util.*;

public class Ex0603 {

   public static void main(String[] args) { //start of main function

   Scanner in = new Scanner(System.in); //creates Scanner class object to take input from user

   int minimum = 0; //stores the minimum of the integers

   int maximum = 0; //stores the minimum of the integers

   int num; //stores the positive integer values

   System.out.println("enter a positive integer: ");//prompts user to enter a positive integer

   num = in.nextInt();//scans and reads the input integer value from user

   minimum = num;  //assigns value of num to minimum

   while(true) {//while loop keeps prompting user to enter a positive integer

       System.out.println("enter a positive integer: ");//prompts user to enter a positive integer

       num = in.nextInt();//scans and reads the input integer value from user

       if(num <=0)//if the user inputs a negative integer or 0

           break; //breaks the loop

       if (num > maximum) {//if the value of positive integer is greater than the maximum of value

           maximum = num; } //assigns that maximum value of num to maximum variable

       if (num < minimum) {//if the value of positive integer is less than the minimum of value

           minimum = num; //assigns that minimum value of num to minimum       }    }            

   System.out.println("The maximum integer is : " + maximum); //displays the maximum of the positive integers

   System.out.println("The minimum integer is : " + minimum); }}   //displays the minimum of the positive integers

Explanation:

Here is the JAVA program that that prompts the user to enter an integer N, then reads N double values, and prints their mean (average value) and sample standard deviation:

import java.util.*;  

public class Ex0603 {  

public static void main(String[] args) { //start of main function

Scanner in = new Scanner(System.in);  //creates Scanner class object to take input from user

double integer= 0;  //to store the number of input values

double sum = 0;  //to store the sum of input numbers

double mean = 0;  //to store the average of numbers

double sd = 0;  //to store the standard deviation result

double variance = 0;  //to store the variance result

double sumSquare = 0;  //to store the sum of (num-mean)^2

int n = 0;  //to store the sample size N

   System.out.println("Enter an integer: ");  //prompts user to enter an integer that is how many elements user wants to input

   integer = in.nextInt();  //reads the value of integer from user

   double size=integer; // declares a double type variable and assigns value of int type variable integer to this double type variable size

   int i=0;  //used to point each element of the num array

   double num[] = new double[(int)size];  //declares an array to hold the numbers input by user

   while(integer>0){  //loop executes until value of integer is greater than 0

   System.out.println("Enter a number: "); // prompts to enter a number

   num[i] = in.nextDouble(); //reads double values

   sum += num[i];  //adds the values stored in num array

   i++;  //increments i to point to the next element in num array

   n++;  //increments n to count the total number of elements

  integer--; //decrements integer value at each iteration

   mean = sum / n;    }  //compute the average of values

   i=0;  

    while(size>0){  //loop executes until value of size exceeds 0

       sumSquare += Math.pow(num[i]-mean,2); //takes the sum of square difference between each element of num array and value of mean

       i++; //increments i

      size--;   }  //decrements size

variance = sumSquare / (n-1);  //compute variance by dividing the result of sum of the squares of their differences from the mean by n-1

   sd = Math.sqrt(variance);  //computes standard deviation by using sqrt function which takes the sqrt of the result of variance computed above

System.out.println("Average value is: " + mean+ " and the standard deviation is " + String. format("%.2f", sd));   }} //displays the average of numbers stored in mean variable and value of standard deviation is displayed up to 2 decimal places

Screenshots of both programs and their outputs is attached.

7 0
3 years ago
Select the correct answer.
True [87]

Answer:

office access cars

Explanation:

<em><u>HOPE</u></em><em><u> </u></em><em><u>THIS</u></em><em><u> </u></em><em><u>WILL</u></em><em><u> </u></em><em><u>HELP</u></em><em><u> </u></em><em><u>U</u></em><em><u>,</u></em><em><u> </u></em><em><u>MARK</u></em><em><u> </u></em><em><u>ME</u></em><em><u> </u></em><em><u>AS</u></em><em><u> </u></em><em><u>A</u></em><em><u> </u></em><em><u>BRAINLIST</u></em>

3 0
2 years ago
How do you insert a table by using standard toolbar?​
MissTica

Answer:

Click the Insert Table button on the Standard Toolbar. Drag over the grid that appears to select the number of rows and columns you want. To use automatic formatting, choose Table AutoFormat from the Table menu. Select several Formats from the menu on the left to see how the table will look.

5 0
2 years ago
To review a printout of a table before printing, on the ____ tab, click print, and then click print preview.
Alex787 [66]
To review a printout of a table before printing, on the FILE tab, click print, and then click print preview. By doing this, you can check, evaluate and do some modifications or changes on your files before having a hardcopy or printouts.
4 0
3 years ago
Two technicians are discussing MAP sensors. Technician A says that the MAP sensor should be replaced if anything comes out of th
anygoal [31]

Answer:

Both are correct.

Explanation:

Both technicians are correct in this scenario. Technician A point of view is correct as well as technician B.

3 0
3 years ago
Other questions:
  • What obstacles could prevent you from getting and keeping a job
    5·1 answer
  • What type of Windows Server is the most likely server to be targeted by a computer hacker?
    13·2 answers
  • When planning your educational and career path, it makes sense to consider where you want to work and what type of work you want
    14·1 answer
  • Which of the following would be an example of a loss of record integrity in a
    12·1 answer
  • write a c++ program that takes a string input from the user and removes all characters except numerals also display the number o
    11·1 answer
  • what social media application that affect our day to day activities, and how did it improve our skill
    9·1 answer
  • In PowerPoint online what can you add to your presentation from the insert tab
    8·2 answers
  • What would you do if you experienced academic frustrations in school? Check all that apply.
    15·2 answers
  • Choose the correct term to complete the sentence.
    10·1 answer
  • What is the name of html command? ​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!