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
What is Frederick Taylor attributed to doing
Wewaii [24]

Answer:

Frederick Winslow Taylor (March 20, 1856 – March 21, 1915) was an American mechanical engineer. He was widely known for his methods to improve industrial efficiency.[1] He was one of the first management consultants.[2] In 1911, Taylor summed up his efficiency techniques in his book The Principles of Scientific Management which, in 2001, Fellows of the Academy of Management voted the most influential management book of the twentieth century.[3] His pioneering work in applying engineering principles to the work done on the factory floor was instrumental in the creation and development of the branch of engineering that is now known as industrial engineering. Taylor made his name, and was most proud of his work, in scientific management; however, he made his fortune patenting steel-process improvements. As a result, Scientific management is sometimes referred to as Taylorism.

Explanation:

7 0
2 years ago
What is an objective of state-sponsored attackers?
Keith_Richards [23]

Answer:

The correct answer is 2. To Spy on citizens

Explanation:

State-sponsored attackers have particular objectives aligned with either the political, commercial or military interests of their country of origin. Investigation shows that “the reality is that if a determined, state-sponsored adversary wants your data, they’re going to get it unless another state-sponsored entity helps you defend it.”

7 0
3 years ago
Write a SELECT statement that selects all of the columns for the catalog view that returns information about foreign keys. How m
Nutka1998 [239]

Answer:

SELECT COUNT (DISTICT constraint_name)

FROM apd_schema.constraint_column_usage

RUN

Explanation:

General syntax to return a catalog view of information about foreign keys.

SELECT DISTINCT PARENT_TABLE =

           RIGHT(Replace(DC.constraint_name, 'fkeys_', ''),

           Len(Replace(DC.constraint_name, 'fkeys_', '')) - Charindex('_', Replace(DC.constraint_name, 'fkeys_', ''))),

           CHILD_TABLE = DC.table_name,

           CCU.column_name,

           DC.constraint_name,

           DC.constraint_type

FROM apd_schema.table_constraints DC

INNER JOIN apd_schema.constraint_column_usage CCU

           ON DC.constraint_name = CCU.constraint_name

WHERE  DC.constraint_type LIKE '%foreign'

           OR DC.constraint_type LIKE '%foreign%'

           OR DC.constraint_type LIKE 'foreign%'

RUN

6 0
3 years ago
How are mathematics and computer science similar? Discuss any connections between numbers, logic, and other elements.
tester [92]

Answer:

Explanation:

Both mathematics and computer science use variables and logic in order to analyze, explain, and model real-world problems. Also mathematics is a very important part of computer science as the logic and algorithms in computer science require mathematics in order to device systems to solve these problems. For example, data structures in computer science require lots of linear algebra in order to traverse large data collections efficiently, while Artificial Intelligence would need calculus and linear algebra in order for it to be efficient.

7 0
3 years ago
Distinguish the functional requirements an engineer would have to specify for a taxi dispatch system.
AveGali [126]
The requirements are mainly written in a feature style notation, using some state charts, context diagrams and other techniques to describe certain parts of the system. See, for example, Software Requirements - Styles and Techniques [Lauesen00].
The functional requirements are divided into four sections. The three modules in figure 1 are developed by separate groups, each responsible for unit testing. All requirements for the taxi, central and communication link component are written in a feature style notation. In addition, a special part of the taxi component is the positioning system. This is dealt with separately since there are special requirements present on this component. The functional requirements consist of four sections: Taxi (3.1), Central (3.2), Communication link (3.3) and Positioning system (3.4). 
6 0
3 years ago
Other questions:
  • Which component is the smallest unit in a spreadsheet?
    14·2 answers
  • Write a program that checks for car mileage. if the mileage is greater than 100000, display "clunker!". if not, display "buy it!
    7·1 answer
  • What process combines data from a list with the content of a document to provide personalized documents?
    9·2 answers
  • 5. RAM IS YOUR SYSTEM’S-
    14·2 answers
  • Which command do you use to save a document with a new name? Choose the answer.
    10·2 answers
  • Research and build a chroot jail that isolates ssh users who belong to the restrictssh group. (You will also need to create the
    9·1 answer
  • Write a function template that accepts an argument and returns its absolute value. The absolute value of a number is its value w
    11·1 answer
  • Select the correct answers
    9·1 answer
  • The code on the side is a software solution to the mutual exclusion problem for two processes. It shares two variables:
    11·1 answer
  • In a List of Positive Integers, Set MINIMUM to 1. For each number X in the list L, compare it to MINIMUM. If X is smaller, set M
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!