Your task is to create a function that simulates a vending machine. Given an amount of money (in cents & to make it simpler) and a product Number, the vending machine should output the correct product name and give back the correct amount of change. The coins used for the change are the following: [500, 200, 100, 50, 20, 10] The return value is an object with 2 properties: product: the product name that the user selected. • change: an array of coins (can be empty, must be sorted in descending order). Examples vendingMachine (products, 200, 7) vendingMachine (products, 500, 0) "Enter a valid product number" vendingMachine (products, 90, 1) → "Not enough money for this product" - - {product: "Crackers", change: [50, 20, 10

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter9: Records (struct)
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question
Your task is to create a function that simulates a vending machine.
Given an amount of money (in cents ¢ to make it simpler) and a product Number, the vending
machine should output the correct product name and give back the correct amount of
change.
The coins used for the change are the following: [500, 200, 100, 50, 20, 10]
The return value is an object with 2 properties:
• product: the product name that the user selected.
change: an array of coins (can be empty, must be sorted in descending order).
Examples
vendingMachine (products, 200, 7)
vending Machine (products, 500, 0) → "Enter a valid product number"
vendingMachine (products, 90, 1) "Not enough money for this product"
→
{product: "Crackers", change: [50, 20, 10
Transcribed Image Text:Your task is to create a function that simulates a vending machine. Given an amount of money (in cents ¢ to make it simpler) and a product Number, the vending machine should output the correct product name and give back the correct amount of change. The coins used for the change are the following: [500, 200, 100, 50, 20, 10] The return value is an object with 2 properties: • product: the product name that the user selected. change: an array of coins (can be empty, must be sorted in descending order). Examples vendingMachine (products, 200, 7) vending Machine (products, 500, 0) → "Enter a valid product number" vendingMachine (products, 90, 1) "Not enough money for this product" → {product: "Crackers", change: [50, 20, 10
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning