ATM CodeChef Solution

Problem – ATM CodeChef Solution

Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja’s account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US.

Calculate Pooja’s account balance after an attempted transaction.

Input

Positive integer 0 < X <= 2000 – the amount of cash which Pooja wishes to withdraw.

Nonnegative number 0<= Y <= 2000 with two digits of precision – Pooja’s initial account balance.

Output

Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.

Example – Successful Transaction

Input:
30 120.00
Output:
89.50

Example – Incorrect Withdrawal Amount (not multiple of 5)

Input:
42 120.00
Output:
120.00

Example – Insufficient Funds

Input:
300 120.00
Output:
120.00

ATM CodeChef Solution in C++17

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(2);

    int a;
    float b;
    cin >> a >> b;
    
    if ((a%5==0) && (b-a-0.5>=0))
    {
        cout << fixed << b-a-0.5 << endl;
    }
    else
    {
        cout << fixed << b << endl;
    }

    return 0;
}

ATM CodeChef Solution in Pyth 3

n,atm=map(float,input().split())
n=int(n)
if (n+0.5<=atm and n%5==0):
    print(float(atm-n-0.5))
else:
    print(float(atm))

ATM CodeChef Solution in Java

import java.util.*;
import java.io.*;

class Solution{
    public static void main(String[] args) throws Exception{
        InputStreamReader i = new InputStreamReader(System.in);
        BufferedReader bf = new BufferedReader(i);
        String[] in = bf.readLine().split(" ");
        float n = Float.parseFloat(in[0]);
        float f = Float.parseFloat(in[1]);
        
        if(n%5==0 && f>=n+0.5f)
        System.out.println(f-n-0.5f);
        
        else{
            System.out.println(f);
        }
        
    }
}

ATM CodeChef Solution Review:

In our experience, we suggest you solve this ATM CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the ATM CodeChef Solution

Find on CodeChef

Conclusion:

I hope this ATM CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *