Challenge 6c

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

  1. 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.
  2. Write a function called double get_money_min(string prompt, double minimum). This function asks the user for a value that is at least the value of minimum. If the user enters a number that’s less than the minimum, then display an error message (think input validation, See sample interaction). It’s OK to use cin/cout in this function.
  3. In main(), use the function get_money() to ask the user to enter a total. See below:
    total = get_money("Enter a total: ");
    
  4. In main(), use the function get_money_min() to ask the user to enter the amount tendered, passing in total as the second parameter.
    tendered = get_money_min("Enter amount tendered: ", total);
    
  5. Declare int quarters, dimes, nickels, pennies in main. These will be used as variables to be passed by reference in the calc_change() function. Initialize all of these variables to zero.
  6. 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. The value change contains the amount of change; this amount can contain dollars and cents. When calculating how many coins for each of the denominations, make sure to only calculate for the actual coins (think of the grocery store, if your change is $1.66, you get the coins equivalent of 66 cents. The $1.00 is given as dollar bills. It is the 66 cents that you want to split up into quarters, nickels, etc). HINT: declare an int variable called centsSet cents = change * 100;  // why? 
  7. 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.34
Enter amount tendered: 20.00
*** Amount must be at least 20.34
Enter amount tendered: 22.00

Your change is $1.66. 

You should have 2 quarter(s), 1 dime(s), 1 nickel(s), and 1 penny/ies. 

Extra Challenge

Have your output be English-friendly, as below:

You should have 2 quarters, 1 dime, 1 nickel, and 1 penny. 

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0006c

Print Requirements