← Encapsulation, const Correctness & static Members

Withdraw with Validation

medium

Complete withdraw so it refuses to overdraw the account: if amount is more than the current balance, print Rejected and leave balance untouched; otherwise, subtract amount normally.

This is what private data was for: because nothing outside BankAccount can touch balance directly, withdraw is the only path that can change it, which means it’s the one place capable of enforcing this rule at all. Direct field access (as if balance were public) could never have stopped an overdraw – there’d be no function in the way to say no.

Your solution

"Run" uses the sample stdin ("100 30"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution