Classwork 17: Reference Parameters
Objectives
To practice implementing a function with reference parameters.
Assignment
Your assignment is to implement a simple function, called makechange(), that figures out how to make change for a given number of cents. Here's a sample run of the program:
PT[127]% ./a.out This program will figure out the change for you. Enter number of cents: 68 Make change using 2 quarters, 1 dimes, 1 nickles and 3 pennies. PT[128]%
In this example, the function makechange() determined that 2 quarters, 1 dime, 1 nickle and 3 pennies equals 68 cents. (This is the fewest number of coins you can have to make up 68 cents.) The function "communicates" this result to the main program using 4 reference parameters.
The function that you implement must be compatible with the main program in this file: makechange.c.
First, download the main program in the file makechange.c. Make sure you save it with a filename that ends with .c.
Below the main program, write the C code to implement the makechange() function. Give meaningful names to your parameters. Give the reference parameters names that immediately tell you they are pointers to int.
To compute the number of quarters, dimes, nickels and pennies, you should use the integer division operator / and the modulus operator %.
Compile and run your program. Use the -Wall option with gcc. Your program should compile without any warnings or errors.
Submitting
Use the script command to record yourself compiling and running the program. Run your program several times! Submit your C source code and the typescript file as usual:submit cs104_chang cw17 makechange.c submit cs104_chang cw17 typescript
Be sure to logout completely when you have finished!