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 development of online capabilities created the ________, an information- and communication-based electronic exchange environ
Reil [10]

It should be noted that development of online capabilities created the marketspace, where an information- and communication-based electronic exchange is been done.

The digital market place  serves as the environment occupied by sophisticated computer and telecommunication technologies and digital offerings.

<h3>What is a marketspace?</h3>

marketspace can be regarded as a place where buying and selling takes place and this could be digital in nature.

Learn more about marketspace at;

brainly.com/question/11408596

5 0
2 years ago
Which shortcut key aligns text to the center of the paige
borishaifa [10]

Answer:

ctrl e then ctrl r

Explanation:

i used google cause im a. gooooddddddddd

6 0
3 years ago
Sending a employee an email with important criticism represents a problem which communication process
Evgen [1.6K]
<span>I am definitely sure that sending an employee an email with important criticism represents a problem in message channel. Message channel is one of the ways through which two parties (manager-employee) communicate with each other.</span>
7 0
3 years ago
What could have made you redesign your plan? Select 3 options.
Masteriza [31]

Answer:

so that their username will still be used and so the can renember the username

Explanation:

that is why

5 0
2 years ago
Tuklasin<br>awain 2: Grapiko ng Pananagutan<br>Isulat sa graphic organizer pa​
mrs_skeptik [129]
What are you saying????
7 0
2 years ago
Other questions:
  • Create a program that reads words.txt (link near top of our home page) in order to: determine the length of the longest word(s)
    14·1 answer
  • All of the following activities may infect your computer with a virus EXCEPT ________.
    6·1 answer
  • Your help will help me understand my answers by comparing to yours. Your kind contribution is very much appreciated.
    6·1 answer
  • Hi, I just have a few questions from my digital tech assignment.
    14·2 answers
  • What will be result of below if statement.
    13·1 answer
  • Name the application used for creating Presentations___
    5·2 answers
  • ¡Hola! He visto en muchos comentarios de Twitter "svd" cuando alguien dice "dale fav a este Tweet y siganse entre ustedes" y en
    8·1 answer
  • Can someone please give me timetable managment system with data structures in java?
    11·2 answers
  • Who is famous for his three laws of robotics?
    9·1 answer
  • If you were a hackathon team manager, how could you best address the conflict created by having more volunteers than open roles
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!