Write a program that inputs a value for N and outputs how many chocolate bars we can eat and how many coupons we would have leftover. Use a loop that continues to redeem coupons as long as there are enough to get at least one chocolate bar.

Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. We can redeem 6 coupons for one chocolate bar from the machine. This means that once you have started buying chocolate bars from the machine, you always have some coupons. We would like to know how many chocolate bars can be eaten if we start with N dollars and always redeem coupons if we have enough for an additional chocolate bar.

For example, with 6 dollars we could consume 7 chocolate bars after purchasing 6 bars giving us 6 coupons and then redeeming the 6 coupons for one bar. This would leave us with one extra coupon. For 11 dollars, we could have consumed 13 chocolate bars and still have one coupon left. For 12 dollars, we could have consumed 14 chocolate bars and have two coupons left.


Students often attempt this problem by trying to find a simple formula instead of simulating the process in a loop. This also makes a good problem to re-do later after


See the code in ChocolateCoupons.java.

Computer Science & Information Technology

You might also like to view...

What does the ScriptEngine function do?

a) It compiles the current script. b) It returns information about the version of VBScript. c) It returns information about the interpreter. d) It returns the type script being used.

Computer Science & Information Technology

A list of cited works in a report or research paper, also referred to as Works Cited, Sources, or References, depending upon the report style.

A. Footnotes B. Citation C. Bibliography

Computer Science & Information Technology

Storing the characters in an input mask requires more disk space, so it is not recommended.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Pointers can be used for all of the following except

A. to locate the subschema address of the record. B. to locate the physical address of the record. C. to locate the relative address of the record. D. to locate the logical key of the record.

Computer Science & Information Technology