ATM , why this is giving wrong answer here?



#include <stdio.h>
#include <stdlib.h>

int main()
int x;
float y;
return 0;


Here are the corrections:

  1. You are first supposed to take x(amount to be withdrawn) as input and then y(balance). But you are first taking y as input and then x.
  2. The extra 0.5 is also to be deducted from the balance, so this changes the condition in the inner if.

    Correction: if((x%5==0)&&x>=0&&x<=2000&&x+0.5<=y)
    [x<=y changed to x+0.5<=y]

    Here is the corrected solution:

There is also no need for checking x>=0&&x<=2000 and also y>=0&&y<=2000, these values simply tell you the range of the input for the problem. There are known as constraints.
The use of constraints:
The most basic use of constraints is that they let you decide the type of data type to use. Suppose if 0<=x<=1012, then you had to declare x as long long instead of int.
In more complex problems they help you decide the algorithm to use to solve the problem based on the time limit. You calculate the time complexity and check from the constraints that it will execute in the time limit specified.

So, there is no need for these checks, the input will definitely be in this range only.

Here is the solution without these checks: