ATM: showing wrong answer

,

#include<stdio.h>

int main()
{
 int x;float y;
 scanf("%d %f",&x,&y);
 if(x%5==0 && x>0 && x<=2000 && y>0 && y<=2000)
  printf("%f",y-x-0.50);
 else
  printf("%f",y);
 return 0;
}

This code is showing wrong answer for ATM. Please help

Your problem - after each line of output, you must print ā€œend-of-lineā€ character. In C++ is represented with character ā€˜\nā€™. Maybe you donā€™t see difference on your machine, but itā€™s a huge difference for tester, because he expected end-of-line.

So the correct code should looks like this:

if(x%5 == 0) printf("%f\n",y-x-0.5);
else printf("%f\n",y);

Now you can see, that I donā€™t use condition x>0 && x<=2000 && y>0 && y<=2000. Thatā€™s because these constraints are secure in statement. Statement says, that these conditions are met for x and y on input. You donā€™t need to verify them.

@niveda90 : You need to check if( ((x%5)==0) && (y>=(x+0.5)) , for correct answer .

1 Like