Answer:
The following is the C code annotated with suitable comments.
Explanation:
#include<stdio.h>
//constants defined
#define DOLLAR 100
#define QUARTER 25
#define DIME 10
#define NICKEL 5
#define PENNIES 1
//method for converting
void ExactChange(int userTotal,int coinVals[])
{
//dollar calculation
if (userTotal >=100)
{
coinVals[0]=userTotal/DOLLAR;
userTotal=userTotal-(100*coinVals[0]);
}
//quarter analysis
if (userTotal >=25)
{
coinVals[1]=userTotal/QUARTER;
userTotal=userTotal-(25*coinVals[1] );
}
//dime check
if (userTotal >=10)
{
coinVals[2]=userTotal/DIME;
userTotal=userTotal-(10*coinVals[2]);
}
//nickel check
if (userTotal >=5)
{
coinVals[3]=userTotal/NICKEL;
userTotal=userTotal-(5*coinVals[3]);
}
//pennies check
if (userTotal >=1)
{
coinVals[4]=userTotal/PENNIES;
userTotal=userTotal-coinVals[4];
}
}
//main function
int main() {
//variables defined
int amount;
//requesting user input
printf("Enter the amount in cents:");
//input registration
scanf("%d",&amount);
//input validation
if(amount<1)
{
//output message
printf("No change..!");
}
//if the input is positive
else
{
int coinVals[5]={0,0,0,0,0};
ExactChange(amount,coinVals);
//checking for dollars
if (coinVals[0]>0)
{
//output for dollars
printf("%d Dollar",coinVals[0]);
if(coinVals[0]>1) printf("s");
}
//checking quarters
if (coinVals[1]>0)
{
//output for quarters
printf(" %d Quarter",coinVals[1]);
if(coinVals[1]>1) printf("s");
}
//checking dimes
if (coinVals[2]>0)
{
//output for dimes
printf(" %d Dime",coinVals[2]);
if(coinVals[2]>1) printf("s");
}
//checking nickels
if (coinVals[3]>0)
{
//printing nickels
printf(" %d Nickel",coinVals[3]);
if(coinVals[3]>1) printf("s");
}
//checking pennies
if (coinVals[4]>0)
{
//printing pennies
printf(" %d Penn",coinVals[4]);
if(coinVals[4]>1) printf("ies");
else printf("y");
}
}
//end of the main function
}