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
mart [117]
3 years ago
6

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:

0
or less, output:

no change
Ex: If the input is:

45
the output is:

1 quarter
2 dimes
Your program must define and call the following method. Positions 0-4 of coinVals should contain the number of dollars, quarters, dimes, nickels, and pennies, respectively.
public static void exactChange(int userTotal, int[] coinVals)
Computers and Technology
1 answer:
sweet [91]3 years ago
7 0

Answer:

#include<stdio.h>

#define DOLLAR 100

#define QUARTER 25

#define DIME 10

#define NICKEL 5

#define PENNY 1

void calculatedChange(int userAmount,int coinValues[])

{

if (userAmount >=100)

{

coinValues[0]=userAmount/DOLLAR;

userAmount=userAmount-(100*coinValues[0]);

}

if (userAmount >=25)

{

coinValues[1]=userAmount/QUARTER;

userAmount=userAmount-(25*coinValues[1] );  

}

if (userAmount >=10)

{

coinValues[2]=userAmount/DIME;

userAmount=userAmount-(10*coinValues[2]);

}

if (userAmount >=5)

{  

coinValues[3]=userAmount/NICKEL;

userAmount=userAmount-(5*coinValues[3]);

}

if (userAmount >=1)

{

coinValues[4]=userAmount/PENNY;

userAmount=userAmount-coinValues[4];

}

}

int main() {

int amount;

printf("Enter the amount in cents :");

scanf("%d",&amount);

if(amount<1)

{

printf("No change..!");

}

else

{

int coinValues[5]={0,0,0,0,0};

calculatedChange(amount,coinValues);

if (coinValues[0]>0)

{

printf("%d Dollar",coinValues[0]);

if(coinValues[0]>1) printf("s");

}

if (coinValues[1]>0)

{

printf(" %d Quarter",coinValues[1]);

if(coinValues[1]>1) printf("s");

}

if (coinValues[2]>0)

{

printf(" %d Dime",coinValues[2]);

if(coinValues[2]>1) printf("s");

}

if (coinValues[3]>0)

{

printf(" %d Nickel",coinValues[3]);

if(coinValues[3]>1) printf("s");

}

if (coinValues[4]>0)

{

printf(" %d Penn",coinValues[4]);

if(coinValues[4]>1) printf("ies");

else printf("y");

}

}

}

Explanation:

  • Create a calculatedChange method for calculating userAmount.  
  • Use conditional statements to check dollars , quarters , dimes , nickels  and penny.
  • Inside the main method , validate the input  and then  print dollars , dimes , nickels after checking them.

You might be interested in
One way to protect against a security threat to a computer system is to __________. Avoid external links with inconsistent URLs
Makovka662 [10]

One way to protect against a security threat to a computer system is to Avoid external links with inconsistent URLs.

<h3>What is malware?</h3>

Malware is any programme that is purposely designed to disrupt a computer, server, client, or computer network, leak private information, obtain unauthorised access to information or systems, deny users access to information, or otherwise interfere with the user's computer security and privacy.

One way to protect against a security threat to a computer system is to Avoid external links with inconsistent URLs. The reason for this is that such links may contain malware or spyware.

Learn more about Malware:

brainly.com/question/14276107

#SPJ1

7 0
2 years ago
Suppose you want to delete an existing file from within word. What would you do?
Oksana_A [137]
Go in to ur files and find the file and delete it
5 0
3 years ago
HELP PLEASE!!!! Which development method is best explained in this way: developing a system through repeated cycles and smaller
vlada-n [284]

Answer:

Incremental method.

Explanation:

Software development life cycle (SDLC) can be defined as a strategic process or methodology that defines the key steps or stages for creating and implementing high quality software applications.

An incremental model refers to the process in which the requirements or criteria of the software development is divided into many standalone modules until the program is completed.

Hence, an incremental method typically involves developing a system through repeated cycles and smaller portions at a time, enhancing and evolving the system over time.

In SDLC, a waterfall model can be defined as a process which involves sequentially breaking the software development into linear phases. Thus, the development phase takes a downward flow like a waterfall and as such each phase must be completed before starting another without any overlap in the process.

Also, a spiral model can be defined as an evolutionary SDLC that is risk-driven in nature and typically comprises of both an iterative and a waterfall model. Spiral model of SDLC consist of these phases; planning, risk analysis, engineering and evaluation.

8 0
3 years ago
Kim agrees. You get the equipment from the truck and begin working. Kim approaches you as you are installing the modem and is a
Angelina_Jolie [31]
Ask your friends if they are doing something wrong with your friends and friends
6 0
1 year ago
Write an application that reads the lengths of the sides of a triangle from the user. compute the area of the triangle using her
zlopas [31]

Here you go,


import java.util.Scanner;

import java.util.Random;

public class OrderCalculator{


public static void main(String[] args){  


float x, y, z, semi, area;

Scanner in = new Scanner(System.in);

System.out.print("Enter the 3 sides: ");

x = in.nextFloat();

y = in.nextFloat();

z = in.nextFloat();

semi = (float) ((x + y + z) / 2.0);

area = (float) Math.sqrt(semi * (semi - x) * (semi - y) * (semi - z));

System.out.printf("The area is: %.3f\n", area);


}

}

3 0
3 years ago
Other questions:
  • The _____ function calculates the average of values in a range that match criteria you specify.
    14·1 answer
  • What type of change can AutoCorrect option make to a word?
    10·2 answers
  • Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
    10·1 answer
  • Mr. Green maintains a spreadsheet containing data on all of his employees, including name, job profile, monthly salary, and home
    15·1 answer
  • You just received a message from the internet which was encrypted with asymmetric encryption. what do you need to do to read the
    12·1 answer
  • Using the _______ list, you can select the number of photos that will appear on each slide.
    13·1 answer
  • The name of a .java file should ______________________________. Always match the name of the Class inside Should always start wi
    9·1 answer
  • What is the family access code right now?
    5·1 answer
  • Hello everyone. New ppl on Ro.blox? I want to play sometime.
    8·2 answers
  • "code is broken down by the computer until it is in _____and is a very long series of ons and offs
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!