Skip to main content

ATM | HS08TEST

Problem

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 Format

Each input contains 2 integers  and .
 is the amount of cash which Pooja wishes to withdraw.
 is Pooja's initial account balance.

Output Format

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.

Constraints

  1. 0<2000 - the amount of cash which Pooja wishes to withdraw.
  2. 02000 with two digits of precision - Pooja's initial account balance.

Sample 1:

Input
Output
30 120.00
89.50

Explanation:

Example - Successful Transaction

Sample 2:

Input
Output
42 120.00
120.00

Explanation:

Example - Incorrect Withdrawal Amount (not multiple of 5)

Sample 3:

Input
Output
300 120.00
120.00

Explanation:

Example - Insufficient Funds


Solution:

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

int main()
{
 
    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;
}

Comments

Popular posts from this blog

Sum of Digits | FLOW006

  Problem You're given an integer  N . Write a program to calculate the sum of all the digits of  N . Input Format The first line contains an integer  T , the total number of testcases. Then follow  T  lines, each line contains an integer  N . Output Format For each test case, calculate the sum of digits of  N , and display it in a new line. Constraints 1 ≤ � ≤ 1000 1 ≤ T ≤ 1000 1 ≤ � ≤ 1000000 1 ≤ N ≤ 1000000 Sample 1: Input Output 3 12345 31203 2123 15 9 8 Solution: #include <bits/stdc++.h> using namespace std; int main() {     int t;     cin>>t;     while(t--)     {         int n;         cin>>n;         int sum = 0;         while(n!=0)         {             int r = n%10;             sum+= r;           ...

Valid Triangles | FLOW013

  Problem Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees. Input Format The first line contains an integer  T , the total number of testcases. Then  T  lines follow, each line contains three angles  A ,  B  and  C , of the triangle separated by space. Output Format For each test case, display 'YES' if the triangle is valid, and 'NO', if it is not, in a new line. Constraints 1  ≤   T   ≤  1000 1  ≤   A,B,C   ≤  180 Sample 1: Input Output 3 40 40 100 45 45 90 180 1 1 YES YES NO Solution: #include <iostream> using namespace std; int main() { // your code goes here int t; cin>>t; while(t--){     int a,b,c;     cin>>a>>b>>c;     if((a+b+c)==180)         cout<<"YES"; ...

First and Last Digit | FLOW004

Problem If Give an integer  N  . Write a program to obtain the sum of the first and last digits of this number. Input Format The first line contains an integer  T , the total number of test cases. Then follow  T  lines, each line contains an integer  N . Output Format For each test case, display the sum of first and last digits of  N  in a new line. Constraints 1 ≤ � ≤ 1000 1 ≤ T ≤ 1000 1 ≤ � ≤ 1000000 1 ≤ N ≤ 1000000 Sample 1: Input Output 3 1234 124894 242323 5 5 5 Solution: #include<bits/stdc++.h> using namespace std; int main() {    int t;    cin>>t;    while(t--)    {        int n;        cin>>n;        int rem = n%10;        while(n>9)        {            n = n/10;        }        cout<<n+rem<<endl; ...