# 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.

**Examples:**

Input:X = 50, bal = 100.50Output:49.00 Transaction successfulInput:X = 55, bal = 99.00Output:99.00 Transaction unsuccessful

**Approach:** Find out if the transaction can be successful or not.

- 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:

## C++

`// C++ program to find the remaining balance ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the balance ` `void` `findBalance(` `int` `x, ` `float` `bal) ` `{ ` ` ` ` ` `// Check if the transaction ` ` ` `// can be successful or not ` ` ` `if` `(x % 10 == 0 ` ` ` `&& ((` `float` `)x + 1.50) <= bal) { ` ` ` ` ` `// Transaction is successful ` ` ` `cout << fixed << setprecision(2) ` ` ` `<< (bal - x - 1.50) << endl; ` ` ` `} ` ` ` `else` `{ ` ` ` ` ` `// Transaction is unsuccessful ` ` ` `cout << fixed << setprecision(2) ` ` ` `<< (bal) << endl; ` ` ` `} ` `} ` ` ` `int` `main() ` `{ ` ` ` ` ` `int` `x = 50; ` ` ` `float` `bal = 100.50; ` ` ` ` ` `findBalance(x, bal); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the remaining balance ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the balance ` `static` `void` `findBalance(` `int` `x, ` `float` `bal) ` `{ ` ` ` ` ` `// Check if the transaction ` ` ` `// can be successful or not ` ` ` `if` `(x % ` `10` `== ` `0` `&& ((` `float` `)x + ` `1.50` `) <= bal) ` ` ` `{ ` ` ` ` ` `// Transaction is successful ` ` ` `System.out.printf(` `"%.2f\n"` `, bal - x - ` `1.50` `); ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` ` ` `// Transaction is unsuccessful ` ` ` `System.out.printf(` `"%.2f\n"` `, bal); ` ` ` `} ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `x = ` `50` `; ` ` ` `float` `bal = (` `float` `) ` `100.50` `; ` ` ` ` ` `findBalance(x, bal); ` `} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find the remaining balance ` ` ` `# Function to find the balance ` `def` `findBalance(x,bal): ` ` ` ` ` `# Check if the transaction ` ` ` `# can be successful or not ` ` ` `if` `(x ` `%` `10` `=` `=` `0` `and` `(x ` `+` `1.50` `) <` `=` `bal): ` ` ` ` ` `#Transaction is successful ` ` ` `print` `(` `round` `(bal ` `-` `x ` `-` `1.50` `, ` `2` `)) ` ` ` `else` `: ` ` ` ` ` `# Transaction is unsuccessful ` ` ` `print` `(` `round` `(bal, ` `2` `)) ` ` ` `# Driver Code ` `x ` `=` `50` `bal ` `=` `100.50` ` ` `findBalance(x, bal) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the remaining balance ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the balance ` `static` `void` `findBalance(` `int` `x, ` `float` `bal) ` `{ ` ` ` ` ` `// Check if the transaction ` ` ` `// can be successful or not ` ` ` `if` `(x % 10 == 0 && ((` `float` `)x + 1.50) <= bal) ` ` ` `{ ` ` ` ` ` `// Transaction is successful ` ` ` `Console.Write(` `"{0:F2}\n"` `, bal - x - 1.50); ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` ` ` `// Transaction is unsuccessful ` ` ` `Console.Write(` `"{0:F2}\n"` `, bal); ` ` ` `} ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `x = 50; ` ` ` `float` `bal = (` `float` `) 100.50; ` ` ` ` ` `findBalance(x, bal); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

**Output:**

49.00

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Program to find the time remaining for the day to complete
- Program to balance the given Chemical Equation
- Balance pans using given weights that are powers of a number
- Area of plot remaining at the end
- Element equal to the sum of all the remaining elements
- Check if the array has an element which is equal to sum of all the remaining elements
- Count the subarray with sum strictly greater than the sum of remaining elements
- Delete odd and even numbers at alternate step such that sum of remaining elements is minimized
- Length of remaining two sides of a Triangle from a given side and its adjacent angles
- Check if the array has an element which is equal to product of remaining elements
- Append a digit in the end to make the number equal to the length of the remaining string
- Find (1^n + 2^n + 3^n + 4^n) mod 5 | Set 2
- Find K such that |A - K| = |B - K|
- Find N from the value of N!
- Find value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find the value of f(n) / f(r) * f(n-r)
- Find 2^(2^A) % B
- Find the value of max(f(x)) - min(f(x)) for a given F(x)
- Find if the Vacation can be taken or not

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.