#C13255. Simple Banking System
Simple Banking System
Simple Banking System
This problem simulates a simple banking system that supports three operations: deposit, withdraw, and balance checking. You are to implement a program that reads a sequence of operations from standard input and performs the corresponding transactions on a bank account. The bank account starts with a balance of 0. The operations include:
- deposit <amount>: Deposit a positive numeric amount into the account. If the amount is not a number or not positive, print an error message. The success message should be in the format:
Deposited \(amount\text{ (formatted to 2 decimals)}\). New balance is \(balance\text{ (formatted to 2 decimals)}\).
- withdraw <amount>: Withdraw a positive numeric amount from the account only if sufficient funds exist. If the amount is not a number, not positive, or exceeds the current balance, print an appropriate error message. The success message should be in the format:
Withdrew \(amount\text{ (formatted to 2 decimals)}\). New balance is \(balance\text{ (formatted to 2 decimals)}\).
- balance: Print the current balance as a floating point number (e.g., 0.0).
Error messages:
- If the amount for deposit is not positive: "Deposit amount must be positive."
- If the amount for withdrawal is not positive: "Withdrawal amount must be positive."
- If the given amount is not a number: "Invalid type for amount. It must be a number."
- If there are insufficient funds for a withdrawal: "Insufficient funds."
Input Constraints: The first line of input contains an integer \(n\) (\(1 \leq n \leq 10^5\)), the number of operations. Each of the following \(n\) lines contains one operation in one of the three formats described.
inputFormat
The input is read from standard input (stdin). The first line contains an integer n representing the number of operations. Each of the next n lines contains an operation command in one of the following formats:
- deposit
- withdraw
- balance
For the deposit and withdraw commands, is supposed to be a number. Any invalid or negative amount should be handled as per the error messages described.
outputFormat
For each operation, output the corresponding result to standard output (stdout) on a new line. The deposit and withdraw operations should output a message indicating the transaction result. The balance operation should output the current account balance.## sample
5
deposit 100.0
deposit 0
withdraw 50.0
balance
withdraw 100
Deposited 100.00. New balance is 100.00.
Deposit amount must be positive.
Withdrew 50.00. New balance is 50.00.
50.0
Insufficient funds.
</p>