Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction The objective of this assignment is to learn how to use variables, operators, expressions, and console input/output. You will write a program that determines

Introduction

The objective of this assignment is to learn how to use variables, operators, expressions, and console

input/output. You will write a program that determines the number of coins of different

denominations () to be returned as change in a vending machine.

Suppose a country issues coins of six different denominations $1, $2, $3, $4, $5, $6 (in decreasing order). When you buy items (e.g., drinks) in a vending machine, you insert money into

the machine, select an item, and the machine will dispense the item and return the change, if any.

Given a particular change amount, a strategy to determine the combination of various coins to be

returned is as follows. First, return the maximum number of the highest denomination ($1). Then,

from the remaining change, return the maximum number of the second highest denomination ($2).

The process continues for the remaining denominations $3, $4, $5, $6. The following shows two examples of returning coins combination.

Sample Run

In the following sample runs, the blue text is user input and the other text is the program printout.

You can try the provided sample program for other input. Your program output should be exactly the

same as the sample program (same text, symbols, letter case, spacings, etc.). Note that there is a

space after the ':' in the program printout.

Enter six decreasing denominations: 100 50 10 5 2 1

Insert money ($): 400

Item price ($): 57

Change is $343

$100 x 3

$50 x 0

$10 x 4

$5 x 0

$2 x 1

$1 x 1

Enter six decreasing denominations: 48 26 12 6 2 1

Insert money ($): 100

Item price ($): 35

Change is $65

$48 x 1

$26 x 0

$12 x 1

$6 x 0

$2 x 2

$1 x 1

Enter six decreasing denominations: 48 26 12 6 2 1

Insert money ($): 160

Item price ($): 160

Change is $0

$48 x 0

$26 x 0

$12 x 0

$6 x 0

$2 x 0

$1 x 0

Enter six decreasing denominations: 7 6 5 4 3 2

Insert money ($): 10

Item price ($): 2

Change is $8

Cannot find combination!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions