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