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.
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.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images