## Description of ATM program  In this ATM program we have to calculate the remaining balance after any transaction. If the balance is sufficient for transaction, we have to print the remaining balance after transaction. But if the balance is insufficient, then we have to print the current balance.

There is also a condition in this ATM program that the ATM machine receives only the withdrawal request of the multiple of 5\$. If the user places the withdrawal request which is not multiple of 5 then we have to print the current balance as the withdrawal is not successful.

This problem is taken from CodeChef for practice and learning purpose of our readers. In this C++ practice article we will discuss about the solution of this problem with source code.

## Solution and source code of ATM program

We will take two input from the user which will be the amount the user want to withdraw and the current balance of his account. As the bank charges 0.50\$ for each successful transaction. We have to consider the total balance is sufficient for withdraw with bank charges.

Imagine, the user gives two number 30 and 120.00.

Then we have to print the remaining balance is

120.00 – (30 + 0.50)

= 89.50

But if the user gives two number such as 300 and 120.00.

Then it is not possible to withdraw the money as the remaining balance is not sufficient for this withdrawal request.

Again, any withdrawal request which is not the multiple of 5, will not be successful. Then we have to print the current balance also.

Now, let’s see the source code for atm problem solving in C++.

``````// solving atm problem by c++

#include <iostream>
#include <iomanip>
using namespace std;

int main(){

int tran;
float newBal;

cin >> tran >> newBal;

if(tran % 5 == 0 && newBal >= (tran + 0.5)){
newBal = newBal - (tran + 0.5);
}

cout << fixed << setprecision(2) << newBal << endl;

}``````

Try to give different input to test the program. You will see the output like this.

``````30 120.00
89.50``````
``````42 120.00
120.00``````
``````300 120.00
120.00``````

For each case in output console, the first number is the amount which the user want to withdraw. The second number is the current balance. Second line contains the output for specific input.

Previous pageSmall factorial

Next pageFind reminder

Recommended for you: