Page 1 of 1

2.1. Consider the following code: double balance; bool withdraw(double amount) { if (amount <= balance) { balance -= amo

Posted: Sun May 15, 2022 1:01 pm
by answerhappygod
2 1 Consider The Following Code Double Balance Bool Withdraw Double Amount If Amount Balance Balance Amo 1
2 1 Consider The Following Code Double Balance Bool Withdraw Double Amount If Amount Balance Balance Amo 1 (31.92 KiB) Viewed 87 times
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?