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
How can i save a word 2016 document as a word 2016 document?
Lana71 [14]
Type 2016 document.pdf.files
3 0
3 years ago
Suppose a classmate constructed an electric motor with a solid commutator.that is, the commutator has no split. This solid commu
professor190 [17]
<span><em>The motor would work if using DC current. The split commutator acts to change the AC to DC for the motor.</em>

<em>                              Hope this helps:)</em>

</span>
3 0
4 years ago
Finding values in an array
hjlf

Answer:

The following code completes the program

for (i = 0; i < userValues.length; i++) {

     if(userValues[i] == matchValue){

         nuMatches++;

     }  }

 System.out.println(nuMatches);

Explanation:

<em>The question is poorly formatted. So, I correct the poorly formatted program segment and I complete the missing part of the program.</em>

<em>See attachment for complete program.</em>

The explanation is as follows:

This iterates through the array

for (i = 0; i < u s e r V a l u e s. length; i++) {

This checks if the current array element is the same as the match value

     if(userValues[i] == matchValue){

If yes, the number of matches is increased by 1

         nuMatches++;

     }  }

This prints the number of matches

 System.out.println(nuMatches);

Download txt
8 0
3 years ago
What does ieee stand for
Ganezh [65]
This stands for institute of electrical and electronics engineers

Good luck!
7 0
3 years ago
Read 2 more answers
Excel recognizes an entry as a value if it is a number or it begins with ____
Sedbober [7]
Excel recognizes an entry as a value if it is a number or it begins with symbol . As symbol in excel are considered the following signs: +, - , =, @, #, or $.
<span> Labels on the other hand are entries that contain text and numerical information not used in calculations.</span>
8 0
4 years ago
Other questions:
  • Which statement about word processing software is true? A)You can use it to perform mathematical calculations.B) You can use it
    6·2 answers
  • Can some one fix this <br> input ("Enter a number: ") <br> print (num * 8)
    9·1 answer
  • To create a default value for a parameter in the parameter list of a function, you code a/an ________________ sign after the par
    5·1 answer
  • :3 Brainlsit included! =) 33 points!
    10·1 answer
  • Which of the following illustrates an example of a string data type?
    15·2 answers
  • Which is one use for a hyperlink? A. to create a heading style B. to animate important text C. to create a link to a website. D.
    7·1 answer
  • You want to substitute one word with another throughout your document. What tool(s) should you use?
    9·1 answer
  • When a primitive type variable is passed as an argument to a method, what is passed into the receiving method's parameter variab
    12·1 answer
  • Tell me the errors please
    14·1 answer
  • Give the names of two different places you might find a number represented in hexadecimal
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!