C++ Program to count the total number of notes in a given amount. Using user define functions

Explanation:

  1. Pass-by-Value (countNotesByValue):
    • Function Definition: void countNotesByValue(int amount, int &notes100, int &notes50, int &notes20, int &notes10, int &notes5, int &notes1)
    • This function takes the amount as input by value (i.e., a copy of the amount).
    • It calculates the number of each type of note (100, 50, 20, 10, 5, 1) needed for the given amount and stores the results in the reference variables (notes100, notes50, etc.).
    • The function uses modulo operations to determine the number of notes for each denomination and updates the remaining amount accordingly.
  2. Pass-by-Reference (countNotesByReference):
    • Function Definition: void countNotesByReference(int amount, int &notes100, int &notes50, int &notes20, int &notes10, int &notes5, int &notes1)
    • This function also takes the amount and updates the reference variables (notes100, notes50, etc.) with the number of notes for each denomination.
    • In this example, it simply calls countNotesByValue to do the actual calculation, demonstrating that pass-by-reference can be used to refer to the same variables.
  3. Main Function (main):
    • The program prompts the user to input an amount.
    • It then counts the notes required using both methods and prints the results.

Example Outputs:

Example 1:

Input:

  • Amount: 273

Output:

Example 2:

Input:

  • Amount: 485

Output:

Example 3:

Input:

  • Amount: 89

Output: