In C Language Write a Program that asks the user to enter a U.S. Dollar amount a
ID: 3804371 • Letter: I
Question
In C Language
Write a Program that asks the user to enter a U.S. Dollar amount and then shows how to pay that amount using the smallest number of $50, $20, $5 and $1 bills: Enter a dollar amount: 228 $50 bills: 4 $20 bills: 1 $5 bills: 1 $1 bills: 3 In this program use the following function: void pay amount (int dollars, int *fifties, int *twenties, int *fives, int *ones) This function determines the smallest number of $50, $20, $5 and $1 bills necessary to pay the amount represented by dollars parameter and prints the results.Explanation / Answer
//The Program Given below
void pay_amount(int dollars,int *fifties,int *twenties,int *fives,int *ones)
{
*fifties=0,*twenties=0,*fives=0,*ones=0;
if(dollars>0)
{
*fifties=dollars/50;
if(*fifties>0)
{
dollars=dollars%50;
}
*twenties=dollars/20;
if(*twenties>0)
{
dollars=dollars%20;
}
*fives=dollars/5;
if(*fives>0)
{
dollars=dollars%5;
}
*ones=dollars/1;
}
//cout<<"fifties"<<fifties<<" "<<"twenties"<<twenties<<" "<<"fives"<<fives<<" "<<"ones"<<ones<<endl;
printf("50$ bills %d ",*fifties);
printf("20$ bills %d ",*twenties);
printf("5$ bills %d ",*fives);
printf("1$ bills %d ",*ones);
}
O/P is lets say dollars entered is 25 then
50$ bills 0
20$ bills 1
5$ bills 1
1$ bills 0