#C14433. ATM Simulator

    ID: 44082 Type: Default 1000ms 256MiB

ATM Simulator

ATM Simulator

You are required to implement a simulation of an Automated Teller Machine (ATM). The ATM starts with a balance of 0 and supports the following operations:

  1. deposit X: Deposit an amount X (a positive number) into the ATM account and then output the new balance.

  2. withdraw X: Withdraw an amount X (a positive number) from the ATM account if sufficient funds are available; otherwise, output error.

  3. balance: Query and output the current balance in the ATM account.

For any deposit or withdrawal operation, if X is not a positive number or, in the case of withdrawal, exceeds the available balance, the operation is invalid and you must output error without changing the balance.

All monetary values must be output as floating point numbers formatted with exactly one digit after the decimal point (e.g. 100.0). Input is provided via stdin and output should be printed to stdout.

The submission will be evaluated against multiple test cases. Good luck!

inputFormat

The input begins with a line containing an integer T (the number of operations).

Each of the next T lines contains a single operation in one of the following formats:

  • deposit X where X is a positive number.
  • withdraw X where X is a positive number.
  • balance

It is guaranteed that the commands are well-formatted.

outputFormat

For each operation, output a line:

  • For a successful deposit or withdraw operation, output the new balance as a floating-point number with one decimal place.
  • For a balance command, output the current balance formatted similarly.
  • If an operation is invalid (i.e. depositing a non-positive amount, or withdrawing a non-positive amount or more than the current balance), output error.## sample
4
deposit 100
balance
withdraw 50
balance
100.0

100.0 50.0 50.0

</p>