ATM using c- Please help

,

I tried ATM problem using c. I am also pretty sure my logic is correct,but there seems to be a minute detail that i have missed.I keep getting my code is worng.
Please help.

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float wit,bal;
scanf("%f %f",&wit,&bal);
if(wit>=bal)
{
printf("%0.2f",bal);
exit(0);
}
if(fmod(wit,5)!=0)
{
printf("%0.2f",bal);
exit(0);
}
else
{
bal=(bal-wit)-0.50;
printf("%0.2f",bal);
}
return 0;
}

please provide question

Your logic is not fully correct.
For example think about the case 100 \space 100 .
Your code will print YES even thought it is visible that this transaction cannot happen, because then you can’t deduct the transaction charges.

else{
		//bal=(bal-wit)-0.50; 
        if(bal >=.5+wit){
        	bal -= wit +.5
        	printf("%0.2f\n",bal)
        }else
           printf("%0.2f\n",ball);
	}

1 Like