Challenge 6

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. Use the function get_money() to ask the user to enter a total. See below:
    total = get_money("Enter a total: ");
    
  3. Use the function get_money() to ask the user to enter the amount tendered.
    tendered = get_money("Enter amount tendered: ");
    
  4. 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.
  5. 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.31
Enter amount tendered: 22.00

Your change is $1.69. 

You should have 2 quarter(s), 1 dime(s), 1 nickel(s), and 4 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