Everything should be made as simple as possible, but not simpler.

Debugging this chocolate bar problem ended up to be very, very difficult
but when I finally got it right it was quite simple.

A "closed form" solution to this problem follows.

candy.tc

Here's what I get for the general case of b dollars and w wrappers for
an extra bar.

A sample run that shows what happens when you launch the main function
and also what happens when you use the new -r option follow the listing.

main [

 int b,w
 pl ""
 pl "dollars : ";b=gn
 pl "number of wrappers to get extra bar : ";w=gn
 pl ""
 choc b,w

 ]

choc int b,w [

 pl "choc.tc - lrb - 3/30/18";pl ""
 int wrappers,tot
 pl ""
 pn b

 if (b>w) [tot=b+b/w;pn tot]

 wrappers=b/w+b%w

 while (wrappers>w) [
  tot=tot+wrappers/w;pn tot
  wrappers=wrappers/w+wrappers%w
  ]
  
 if (wrappers==w) [
  tot=tot+1;pn tot;pl " there is 1 leftover wrapper."
  ]
 else [
  pl " there is/are";pn wrappers;ps " leftover wrappers."
  ]

 pl""
 ]

E:\star>tc choc.tc
***  TINY-C VERSION 1.0,  COPYRIGHT 1977, T A GIBSON  ***
        This C version copyright 2017, T A Gibson


dollars : 15
number of wrappers to get extra bar : 3

choc.tc - lrb - 3/30/18

 15 20 21 22
 there is 1 leftover wrapper.

done

E:\star>tc choc.tc
***  TINY-C VERSION 1.0,  COPYRIGHT 1977, T A GIBSON  ***
        This C version copyright 2017, T A Gibson


dollars : 16
number of wrappers to get extra bar : 3

choc.tc - lrb - 3/30/18

 16 21 23
 there is/are 2 leftover wrappers.

done

E:\star>tc choc.tc
***  TINY-C VERSION 1.0,  COPYRIGHT 1977, T A GIBSON  ***
        This C version copyright 2017, T A Gibson


dollars : 66
number of wrappers to get extra bar : 3

choc.tc - lrb - 3/30/18

 66 88 95 97 98
 there is/are 2 leftover wrappers.

done

E:\star>tc choc.tc -r choc(16,5)
***  TINY-C VERSION 1.0,  COPYRIGHT 1977, T A GIBSON  ***
        This C version copyright 2017, T A Gibson

choc.tc - lrb - 3/30/18

 16 19
 there is/are 4 leftover wrappers.

done

E:\star>tc choc.tc -r choc(1001,314)
***  TINY-C VERSION 1.0,  COPYRIGHT 1977, T A GIBSON  ***
        This C version copyright 2017, T A Gibson

choc.tc - lrb - 3/30/18

 1001 1004
 there is/are 62 leftover wrappers.

done

E:\star>