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 was your first experience with listening to kpop?
Verizon [17]

Answer:

My first experience with kpop was when I was six I just danced to it lol I forgot the name of the song but it was funny watching the video of me.

Explanation:

8 0
3 years ago
Read 2 more answers
Which of the following scenarios demonstrates leadership?
bulgar [2K]
I can’t see the scenarios bro
8 0
3 years ago
Read 2 more answers
What saw do you use to cut wood in design and technology
tia_tia [17]
Your answer would be a coping saw!
Coping saws are most commonly used cutting woof in design and technology! :)

5 0
3 years ago
To output age for the user which of the following you need to use?
koban [17]

Answer:

D

Explanation:

A is declaring a variable

B is getting input from the user and storing it in variable age

C is outputting the word "age" to the screen

D is outputting the word "age" to the screen and then outputting the value of the age variable immediately after which is correct.

6 0
3 years ago
A web page without a bibliography, or sources, is an indicator of an unreliable site.
alisha [4.7K]
A.True because without a source then it could just be made up.......hope this helps :)

5 0
3 years ago
Read 2 more answers
Other questions:
  • What attributes a website indicates a more reliable source for information
    14·1 answer
  • Which type of page of replacement algorithm is Windows XP and Unix are using?
    15·1 answer
  • Write a class called MagicSquare, which contains a single method called check that accepts a two-dimensional array as an argumen
    7·1 answer
  • A user prefers an external monitor, mouse, and keyboard for a laptop. The user does not want to use the built-in screen; however
    5·1 answer
  • Authentication is a mechanism whereby unverified entities or supplicants who seek access to a resource provide a label by which
    12·1 answer
  • Use the drop-down menus to complete the statements about printing Contacts. When printing a single contact, go to File and then
    15·1 answer
  • What is the next line?
    7·1 answer
  • What is the output of the following code:
    12·1 answer
  • Javier downloads an illustration from an online Image library and modifies it for his purposes. The illustration he downloads is
    12·1 answer
  • Select the correct answer.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!