Find the remaining balance after the transaction
Given the initial balance as bal and the amount X to be debited, where X must be a multiple of 10 and rupees 1.50 is deducted as the debit charge for each successful debit. The task is to find the remaining balance left after the transaction, which can be successful, or unsuccessful. The balances are in 2 floating-point precision.
Input: X = 50, bal = 100.50 Output: 49.00 Transaction successful Input: X = 55, bal = 99.00 Output: 99.00 Transaction unsuccessful
Approach: Find out if the transaction can be successful or not.
Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the Demo Class for First Step to Coding Course, specifically designed for students of class 8 to 12.
The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.
- The transaction can be successful if:
- X is a multiple of 10, and
- The person has at least (X+1.50) rupees, that is the money to be withdrawn plus the charges, in the account.
- In any other case, the transaction will be unsuccessful.
- If the transaction is successful, then deduct the (X + 1.50) amount from the balance and return it
- Else just return the balance.
Below is the implementation of the above approach: