Problem 2. Write aprogram change.c that asks how much money a user has, represen
ID: 3923323 • Letter: P
Question
Problem 2. Write aprogram change.c that asks how much money a user has, represented as a double, and prints the smallest number of quarters, dimes, nickels, pennies that constitute this amount. If any coin type is not used, its name is not printed. )$ a.out How much money do you have? 7.43 You have 29 quarter (s), 1 dime (s), 1 nickel (s), 3 penny (ies) )$ a.out How much money do you have?.0.70 You have 2 quarter (s), 2 dime (s) ()$ a.out How much money do you have?.0.11 You have. 1 dime (s), 1 penny (ies) ()$ a.out How much money do you have?.0.05 You have 1 nickel (s)Explanation / Answer
#include<stdio.h>
main()
{
double a,change,c;
int q,d,n,p;
int quarter,dime,nickel,penny;
printf("enter change;");
scanf("%lf",&change);
c=change*100;
quarter = c / 25;
dime = (c - (quarter * 25)) / 10;
nickel = (c - ((quarter * 25) + (dime * 10))) / 5;
penny = (c - ((quarter * 25) + (dime * 10) + (nickel * 5))) / 1;
printf ("There are: %d quarters There are %d dimes There are %d nickels and %d pennies", quarter, dime, nickel, penny);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.