2.1. Consider the following code: double balance; bool withdraw(double amount) { if (amount <= balance) { balance -= amo
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
2.1. Consider the following code: double balance; bool withdraw(double amount) { if (amount <= balance) { balance -= amo
2.1. Consider the following code: double balance; bool withdraw(double amount) { if (amount <= balance) { balance -= amount; return true; } else { return false; } } Is the withdraw operation idempotent? Why or why not? If not, how might you rewrite it so it is? Hint: How would we know if a particular withdrawal was being re-attempted as opposed to a separate, subsequent withdrawal?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!