Why am I getting RUN TIME ERROR ?

#include<stdio.h>
main()
{
int X;
float Y;
scanf("%d %f",&X,&Y);
if((X%5==0)&&(0<X<2000)&&(0<Y<2000)&&(X<=Y-0.50))
{
printf("%0.2f",(Y-X)-0.5);
}
else
printf("%0.2f",Y);
}

no need to check these two conditions (0<X<2000) and (0<Y<2000).remove these two conditions and comment whether it is working fine or not.

3 Likes

I checked your submission. Please tell the error exactly and appropriately. Youa re getting NZEC error and its fixed by doing following changes-

  1. main() to int main()
  2. add a “return 0’” in end.

Here is your accepted code-

#include<stdio.h>
int main()
{
    int X;
    float Y;
    scanf("%d %f",&X,&Y);
    if((X%5==0)&&(0<X<2000)&&(0<Y<2000)&&(X<=Y-0.50))
    {
        printf("%0.2f",(Y-X)-0.5);
    }
    else
    printf("%0.2f",Y);
    return 0;
}

thanks!! it worked.
But what was the problem with those conditions

In coding, in most cases you can’t chain an inequality. Read this

1 Like

if you want to check 0<X<2000 then you should write like this 0<X and X<2000

Oh lol on 2nd look i get it now. He was joining it like 0<X<2000 , and this must have got mistaken for something else by compiler giving runtime error. Even i was thinking where did he made error. Sharp eyes @hruday968 XD

1 Like

haha thanks bro @vijju123

1 Like

BUT, the below code is a random accepted code having bounded conditions.

#include<stdio.h>
    int main()
    {
    	int x;
    	float y,z ;
    	scanf("%d %f",&x,&y) ;
    	if (0 < x < 2000 && 0 < y < 2000){
    		if(x <= ( y - 0.5)){
    			if(x%5 == 0){
    				z=(y-x)-0.5 ;
    			}
    			else{
    			    z = y;
    			}
    			
    		}else{
    				z = y ;
    			}
    		printf("%0.2f",z) ;
    	}
    	return 0;
    	
    }