Another run example: Write a complete C program that prompts for and reads a pos
ID: 3669080 • Letter: A
Question
Another run example:
Write a complete C program that prompts for and reads a positive float value representing a monetary amount; you may assume the value entered is correct (legal). Echo print the value entered rounded to 4 decimal places. Then you are to determine and report the fewest number of each bill and coin needed to represent that amount (assume that a ten-dollar bil is the largest size bill available). Note that you should output counts for all bills and coins:; number of eacn bill and coin needed to represent that amount (assúme that a ten-dollar bi see the sample run below for an example. Make sure you label all of your output exactly as shown in the example runExplanation / Answer
#include <stdio.h>
#include <math.h>
int main(void) {
float amount;
// your code goes here
printf("Amount? ");
scanf("%f",&amount);
int k = amount *10;
int p = ceil(amount *100) - k*10;
printf(" value entered: %.4f",amount);
printf(" $%g =",amount);
int n = amount/10;
printf(" %d ten dollar bills(s)",n);
amount = amount-n*10;
n = amount/5;
printf(" %d five dollar bills(s)",n);
amount = amount-n*5;
n = amount/1;
printf(" %d one dollar bills(s)",n);
amount = amount-n*1;
n = amount/.25;
printf(" %d quarter(s)",n);
amount = amount-n*.25;
n = amount/.10;
printf(" %d dime(s)",n);
amount = amount-n*.1;
n = amount/.05;
printf(" %d nickel(s)",n);
amount = amount-n*.05;
n = amount/.01;
printf(" %d pennies",p);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.