Suppose you can buy chocolate bars from a vending machine for $1 each. Inside every chocolate bar is a coupon. You can redeem 7 coupons for 1 chocolate bar from the machine. For example, if you have $20, you can initially buy 20 chocolate bars. This gives you 20 coupons. You can redeem 14 coupons for 2 additional chocolate bars. These 2 chocolate bars have 2 more coupons, so you now have a total of 8 coupons. This gives you enough to redeem for 1 final chocolate bar. Write a recursive function that would accept the amount of dollars and coupons as its parameters and output the total number of chocolate bars that can be bought (including those redeemed via coupons). Write a test program in C++that would allow the user to enter amount of dollars and then use the recursive function to compute the number of chocolate bars the user can buy, and output the number to the screen.

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter17: Markov Chains
Section: Chapter Questions
Problem 12RP
icon
Related questions
Question

Suppose you can buy chocolate bars from a vending machine for $1 each.
Inside every chocolate bar is a coupon. You can redeem 7 coupons for 1
chocolate bar from the machine.
For example, if you have $20, you can initially buy 20 chocolate bars.
This gives you 20 coupons. You can redeem 14 coupons for 2 additional
chocolate bars. These 2 chocolate bars have 2 more coupons, so you now have a
total of 8 coupons. This gives you enough to redeem for 1 final chocolate bar.
Write a recursive function that would accept the amount of dollars and
coupons as its parameters and output the total number of chocolate bars that
can be bought (including those redeemed via coupons).
Write a test program in C++that would allow the user to enter amount of dollars
and then use the recursive function to compute the number of chocolate bars
the user can buy, and output the number to the screen.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Probability Problems
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
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole