Budget for a dependent fee call

An account initially contains 137 whole credits. The operation debit(k) accepts an integer amount. Its precondition is 1≤k≤old⁡(balance)1\leq k\leq\operatorname{old}(\text{balance}), and its postcondition on normal return is balance=old⁡(balance)−k\text{balance}=\operatorname{old}(\text{balance})-k.


A client first calls debit(n), then calls debit(fee), where


fee=⌈n20⌉ credits.\text{fee}=\left\lceil\frac{n}{20}\right\rceil\ \text{credits}.


The ceiling notation means rounding upward to the nearest integer. The fee is calculated from the original requested amount nn. Assume the first call returns normally and no other operation changes the balance.


What is the largest positive integer nn for which both calls satisfy their preconditions? Answer in whole credits, to zero decimal places.


An account balance feeds a requested debit followed by a fee debit.


Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Design by Contract Questions: