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

Write a C function named change() that accepts a floating point number of total

ID: 3637432 • Letter: W

Question

Write a C function named change() that accepts a floating point number of total coins and the addresses of the integer variables named quarters, dimes, nickels, and pennies. The function should determine the number of quarters, dimes, nickels, and pennies in the total coins number passed to it and write these values directly into the respective variables declared in its calling function using pointers.

Call the function change() from main() three times and print out the contents of the variables quarters, dimes, nickels, and pennies after each function return.

First Call--pass in the total value $1.88 and on return print the contents of the variables.

Second Call--pass in the total value .32 and on return print the contents of the variables.

Third Call--ask for a total value input from the keyboard and on return print the contents of the variables.

Output should look like:
TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies

and not:

TOTAL VALUE ENTERED: 1.88
7 quarters
18 dimes
37 nickels
188 pennies

Explanation / Answer

#include void change(float coin) { float abc = coin*10.0*10.0; int sum = abc; int x,y,z; printf(" TOTAL VALUE ENTERED: %f ",coin); z = sum/25; printf( " %d quarters ",z); sum = sum - z*25; y = sum/10; printf( " %d dime ",y); sum = sum - y*10; x = sum/5; printf( " %d nickels ",x); sum = sum - x*5; printf( " %d pennies ",sum); } int main() { float d; change(1.88); change(0.32); printf(" Enter a value for change :"); scanf("%f",&d); change(d); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote