#C13538. Bank Account Simulation
Bank Account Simulation
Bank Account Simulation
In this problem, you are required to implement a bank account management system. The system starts with an initial balance of $0 and supports three operations:
- deposit X: Deposit the amount X into the account. The amount must be a number, greater than 0 and less than or equal to 10000. If the amount is not a number, print
Invalid deposit amount
. If the amount is less than or equal to 0 or greater than 10000, printDeposit amount must be between 0 and 10000
. - withdraw X: Withdraw the amount X from the account. The amount must be a number, greater than 0 and not more than the current balance. If the amount is not a number, print
Invalid withdraw amount
. If the amount is less than or equal to 0, printWithdraw amount must be positive
. If there are insufficient funds for the withdrawal, printInsufficient funds
. - balance: Print the current balance.
Each operation is provided as a separate command line from the standard input. Your task is to process all operations sequentially and print outputs immediately when a balance
command is encountered or when an error message is triggered by a deposit or withdrawal command.
All numeric comparisons and validation should follow the constraints: deposit amounts must be \(0 < X \le 10000\) and withdrawal amounts must be \(0 < X \le current\ balance\).
inputFormat
The first line of the input contains an integer N
, the number of operations. The following N
lines each contain an operation in one of the following formats:
deposit X
withdraw X
balance
Here, X
represents the amount and may be a string that should represent a valid number.
outputFormat
For each balance
command, print the current balance on a separate line. If an error occurs during a deposit
or withdraw
operation (due to invalid input or violation of constraints), print the corresponding error message immediately.
6
deposit 1000
balance
withdraw 200
balance
deposit 300
balance
1000
800
1100
</p>