ATM ....why wrong answer XX

#include<stdio.h>
int main()
{ unsigned int x=0;
float y;
// printf(“Enter Withdrawal Amount & Account Balance currently “);
scanf(”%d%f”,&x,&y);

    if((x>2000) || (y>2000))
      {   return 0;
       }

  if(x%5==0)
  {  if(y>=(x+0.50))
    {
     y=y-x-0.5;
  	printf("%0.2f\n",y);
   }
   if(y<(x+0.50))
   {  printf("%0.2f\n",y);
   }
  }	
  else 
  
  {   printf("%0.2f\n",y);
  }
  
	
	return 0;
}
1 Like

Check my solution

#include<stdio.h> int main() { int m; float bal; scanf("%d %f",&m,&bal); if(m%5==0 && (m+.5)<=bal) { printf("%.2f\n",bal-m-0.5); } else { printf("%.2f\n",bal); } return 0; }

you are not supposed to print any messages…
Like “Enter this or that”
You should stick to the input & output as stated in the problem statement.
Read the FAQs

The problem lies in your condition satement. What happens when both if condition fails in

if(x%5==0){
 ...
}

block. The best thing you can do is to check like this

if(x%5==0){
 if(y>=(x+0.50))
 {
  y=y-x-0.5;
  printf("%0.2f\n",y);
 }
 else
  printf("%0.2f\n",y);
}
1 Like