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
The nl2br() function can be used to convert new line entries in a text area into html ________________ tags.
SSSSS [86.1K]
<span>The nl2br() function can be used to convert new line entries in a text area into html br tags.</span>
8 0
3 years ago
List 5 anti-virus products currently in use
Angelina_Jolie [31]
Norton Antivirus
BIT DEFENDER
F-secure
Avira
McAfee
6 0
3 years ago
T/F The two primary sections of the CPU are the arithmetic/logic unit and the control unit
sashaice [31]
True because cpu are the arithmetic/logic units and the control unit
4 0
3 years ago
What is required to control access to the file system using file and folder permissions on a windows based computer?
Elis [28]
NFTS-formatted partition.
5 0
3 years ago
Wendy Patel is entering college and plans to take the necessary classes to obtain a degree in architecture. Research the program
jeka57 [31]

Answer:

Follows are the solution to this question:

Explanation:

If Windy needs to study and be a specialist in graphic designing for machines, I'm going to provide a windy link of the machine with such a 64 bit, 3-GHz Intel or AMD processor with an 8 GB  RAM, an OpenGL 4.1 chip, an inter-button cursor, a right thumbstick, or a storage drive with GB at least.  

  • All above description for the computer is suitable for windy because you would well be aware throughout the graphic designing, that may be learned through iRhino 3D (iOS), Autocad, Magical Plan, Morphoio trace, etc if you'd like to graduation in architecture.
  • They require fast internet for each application, that can also be installed and installed, that  often requires a profile of all technical support programs as well as a web-only storage license.  
  • As many of the above applies also runs through an AMD or six-bit intel, but not on the ARM processor or instance  iRhino 3D (iOS) isn't consistent with an Embedded system, I will select the processor like an Intel or 3GHz AMD processor.
4 0
3 years ago
Other questions:
  • What are the 21St century competencies or skills required in the information society?<br>​
    15·1 answer
  • How does applying Fontworks effects to text on an advertising flyer change the text?
    8·1 answer
  • In preparing his persuasive presentation, Reza should most likely focus on clearly presenting his
    6·2 answers
  • What is trouble shoot​
    11·1 answer
  • Which act requires that financial institutions must provide a privacy notice to each consumer that explains what data about the
    12·1 answer
  • Plz tell the answer I I'll mark u as the brainliest
    14·1 answer
  • Website designers work on the code and programming of a website, not the style or layout of the site.
    9·1 answer
  • Help plz!! I will mark brainliest
    15·2 answers
  • You have been on the phone with a user in a remote office for 30 minutes troubleshooting their minor desktop problem. No matter
    6·1 answer
  • What are 3 customizations that can be done using the header/footer section in the customize reports tray?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!