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
ArbitrLikvidat [17]
3 years ago
15

Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per li

ne. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.
Engineering
1 answer:
pshichka [43]3 years ago
6 0

Answer:

The C code is given below with appropriate comments

Explanation:

#include<stdio.h>

//defining constants

#define DOLLAR 100

#define QUARTER 25

#define DIME 10

#define NICKEL 5

#define PENNIES 1

//converting method

void ExactChange(int userTotal,int coinVals[])

{

//checking dollars

if (userTotal >=100)

{

coinVals[0]=userTotal/DOLLAR;

userTotal=userTotal-(100*coinVals[0]);

}

//checking quarters

if (userTotal >=25)

{

coinVals[1]=userTotal/QUARTER;

userTotal=userTotal-(25*coinVals[1] );

}

//checking dimes

if (userTotal >=10)

{

coinVals[2]=userTotal/DIME;

userTotal=userTotal-(10*coinVals[2]);

}

//checking nickels

if (userTotal >=5)

{

coinVals[3]=userTotal/NICKEL;

userTotal=userTotal-(5*coinVals[3]);

}

//checking pennies

if (userTotal >=1)

{

coinVals[4]=userTotal/PENNIES;

userTotal=userTotal-coinVals[4];

}

}

//main method

int main() {

//defining the variables

int amount;

//asking for input

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

//reading the input

scanf("%d",&amount);

//validating the input

if(amount<1)

{

//printing the message

printf("No change..!");

}

//when the input is >0

else

{

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

ExactChange(amount,coinVals);

//checking dollars

if (coinVals[0]>0)

{

//printing dollars

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

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

}

//checking quarters

if (coinVals[1]>0)

{

//printing quarters

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

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

}

//checking dimes

if (coinVals[2]>0)

{

//printing dimes

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

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

}

//checking nickels

if (coinVals[3]>0)

{

//prinitng nickels

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

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

}

//checking pennies

if (coinVals[4]>0)

{

//printing pennies

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

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

else printf("y");

}

}

//end of main method

}

You might be interested in
For the following circuit, V"#$=120∠30ºV.Redraw the circuit in your solution.a.(4) Calculate the total input impedance seen by t
olchik [2.2K]

Answer:

Check the explanation

Explanation:

Kindly check the attached images for the step by step explanation to the question

8 0
3 years ago
(Tacoma Bridge Failure) Are There Relevant Ethical Issues Or Just 20-20 Hindsight?
NemiM [27]

Answer:

i have no idea

Explanation:

7 0
3 years ago
Which of the following statements regarding piston rings is false? Select one: a.
sveta [45]

Compression ring prevents pressurized refrigerant from blowing past the piston into the crankcase is the false statement.

Answer: Option A

<u>Explanation:</u>

Compression rings seal the combustion chamber from crankcase and then transfer heat to the cylinder from the piston. The piston rings are present in an internal combustion engine or steam engine with multi functions. The functions of piston rings are,

  • Ensuring the combustion chamber is tightly sealed as to reduce the loss of gas to crankcase .
  • Promoting heat transfer from the piston to cylinder wall .
  • Controlling engine oil consumption .
  • Optimizing the proper quantity of oil between piston and cylinder wall.
3 0
4 years ago
Develop rough sketches of ideas bridge ​
irga5000 [103]

Answer:

look online

Explanation:

3 0
3 years ago
Briggs &amp; Stratton engines feature both a pressure lubrication and a pressure filtration system. Which statement is true?
Andreyy89
Answer would be Letter B
7 0
3 years ago
Other questions:
  • A hot-water stream at 80°C enters a mixing chamber with a mass flow rate of 0.56 kg/s where it is mixed with a stream of cold wa
    7·1 answer
  • You have a solid square copper ground support, 2 inch per side X 6 inches tall, and it is loaded axially (long axis)with 1600 po
    11·1 answer
  • Diesel engines do not use spark plugs to ignite the fuel-air mixture. Instead, they rely on the compression stroke to raise the
    12·1 answer
  • Block B starts from rest and moves downward with a constant acceleration. Knowing that after slider block A has moved 400 mm its
    13·1 answer
  • For a turning operation, you have selected a high-speed steel (HSS) tool and turning a hot rolled free machining steel. Your dep
    9·1 answer
  • At steady state, a valve and steam turbine operate in series. The steam flowing through the valve undergoes a throttling process
    9·1 answer
  • State two faults that are common in a simple cell​
    6·2 answers
  • Harlin is designing a new car engine that does not create pollution. Which technological design factor is probably the most
    8·1 answer
  • Which work practice should be followed to best prevent the ingestion of chemicals?
    7·1 answer
  • Which explanation best summarizes what went wrong during Paul’s cost analysis?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!