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

For each of the programs assigned below, submit a copy of the source code (.c fi

ID: 3825190 • Letter: F

Question

For each of the programs assigned below, submit a copy of the source code (.c file-not a Word document) Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition, when functions are required, place function definitions following main. Before each function use comments to explain what the function does. Do not use global variables. Write a program to determine change from a $20 bill used to purchase an item. In function main prompt the user for the cost of an item (less than $20). Call a function to determine and return using pointers the least number of dollars, quarters, dimes, nickels, and pennies to be returned as change to the shopper. Print the number of dollars and of each type of coin in function main (In some cases you may be a penny off; this is rounding error.)

Explanation / Answer

//Please find Program as well as copied output.

#include <stdio.h>

//Calculation part
void Calculate(int val, int* remaining, int* cnt)
{
*cnt = (int) (*remaining/val);
*remaining = (*remaining)%val;
}

int main(void) {
double cost;
int remaining;
int cnt;
   printf(" Please enter cost of an item(less than $20): ");
   scanf("%lf",&cost);
  
  
   remaining=cost*100; //Took value by considering 1 dollar=100 Penny, so that rounding error will not occur

  //Dollar Count
   Calculate(100, &remaining, &cnt);
   printf(" Dollar Count : %d",cnt);
  
   //Quarter Count
   Calculate(25, &remaining, &cnt);
   printf(" Quarter Count : %d",cnt);
  
   //Dime Count
   Calculate(10, &remaining, &cnt);
   printf(" dime Count : %d",cnt);
  
   //Penny Count
   Calculate(5, &remaining, &cnt);
   printf(" Penny Count : %d",cnt);
  
   //Nickel Count
   Calculate(1, &remaining, &cnt);
   printf(" Nickel Count : %d",cnt);
  
   return 0;
}

//Output Details
/*
Please enter cost of an item(less than $20): 10.25
Dollar Count : 10
Quarter Count : 1
dime Count : 0
Penny Count : 0
Nickel Count : 0
*/