Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program to dispense change. The user enters the amount paid and the amou

ID: 3545793 • Letter: W

Question

write a program to dispense change. The user enters the amount paid and the amount due. The program determines how many dollars, quarters, dimes, nickels, and pennies should be given as change. Write a function with four output parameters that determines the quantity of each kind of coin.



a) Write the function proto-type for the function change() that takes as input the amount of money that should be returned to the user and gives as output the number of dollars, quarters, dimes, nickels, and pennies.



c.) When you ask for the amount paid, ensure that it is at least as much as the amount due.


d. Below is a sample run:


*** Change Calculator ***

Amount due: $ 38.06

Amount paid: $ 20.00

Invalid ($ 20.00 < $ 38.20)

Amount paid: $ 50.00

The change is:

11 dollar(s)

3 quarter(s)

1 dime(s)

1 nickel(s)

4 penny(ies)



Explanation / Answer

#include<stdio.h>
void change(float amount,int* dollars,int* quarters,int* dimes,int* nickels,int* pennies)
{
int left_amount =0;
*dollars = amount;
left_amount =(amount-*dollars)*100+0.5;
*quarters = left_amount/25;
left_amount = left_amount - 25*(*quarters);
*dimes = left_amount/10;
left_amount = left_amount - 10*(*dimes);
*nickels = left_amount/5;
*pennies = left_amount - 5*(*nickels);
}
int main()
{
printf(" *** Change Calculator ***");
float amount_due;
float amount_paid;
int dollars,quarters,dimes,nickels,pennies;
printf(" Amount due: $ ");
scanf("%f",&amount_due);
printf(" Amount paid: $ ");
scanf("%f",&amount_paid);
while(amount_paid < amount_due)
{
printf(" Invalid ($ %.2f < $ %.2f)",amount_paid,amount_due);
printf(" Amount paid: $ ");
scanf("%f",&amount_paid);
}
change(amount_paid-amount_due,&dollars,&quarters,&dimes,&nickels,&pennies);
printf(" The change is: ");
if(dollars!=0)
printf(" %2d dollar(s)",dollars);
if(quarters!=0)
printf(" %2d quarter(s)",quarters);
if(dimes!=0)
printf(" %2d dime(s)",dimes);
if(nickels!=0)
printf(" %2d nickel(s)",nickels);
if(pennies!=0)
printf(" %2d penny(ies)",pennies);
return 0;
}