Description
The purpose of this challenge is to use function parameters passed by reference. This challenge simulates a coin change return machine like the ones found at the grocery store.
Requirements
- Write a function called double get_money(string prompt). This function will prompt the user to enter a positive monetary value. This function should continue to prompt the user as long as negative numbers are entered. The prompt parameter is the text that is displayed to the user. It’s OK to use cin/cout in this function.
- Write another function also called double get_money(string prompt, double minimum). This is an overloaded version of the function in Step 1. This version ensures that the amount entered by the user within the function and returned by the function is at least the value of minimum. It’s OK to use cin/cout in this function.
- Use the function get_money() to ask the user to enter a total. See below:
total = get_money("Enter a total: ");
- Use the function get_money() to ask the user to enter the amount tendered, passing in total as the second parameter.
tendered = get_money("Enter amount tendered: ", total);
- Declare a function void calc_change(double change, int & quarters, int & dimes, int & nickels, int & pennies). The calc_change() function will calculate how many coins will be needed as change.
- Remember that main() will be responsible for displaying the results of calc_change(). (DO NOT have any couts in calc_change())
Sample Interaction / Output
Enter a total: 20.32 Enter amount tendered: 20.00 *** Amount must be at least 20.32 Enter amount tendered: 22.00 Your change is $1.68. You should have 2 quarter(s), 1 dime(s), 1 nickel(s), and 3 penny/ies.
Extra Challenge
Have your output be English-friendly, as below:
You should have 2 quarters, 1 dime, 1 nickel, and 4 pennies.
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0006
Print Requirements