# ATM: Getting wa

#include <stdio.h>

``````int main()
{
int i;
float bal=120;
//printf("Enter the amt to be withdrawed");
scanf("%d",&i);
if((i%5)==0)
{
if(i<bal)
bal=bal-i-0.5;

}
printf("%.2f",bal);
return 0;
}``````
1 Like

it return incorrect output for

``200 300.00``

sir,I ran the output for 200.It was correct.The if statement will definitely prevent it.Right??

try 300.00 300.00
And also both â€śiâ€ť and â€śbalâ€ť are inputâ€¦ Read it againâ€¦

@sabarish :: There are a couple of mistakes in your code.

(1).You are only taking one input instead of two.
The program should asks two inputs -

``````X=Amount pooja wants to withdraw from an ATM.
Y=Balance in the atm.

Your program is only taking the input X (scanf("%d",&i)) but it is not taking the input Y(You have fixed the bal value to 120 ,every time your program assumes that pooja has 120 USD as balance in ATM and yes this  one of the two reasons behind Wrong Answer.
``````

So take balance as input too.

A transaction is possible if Poojaâ€™s account balance has enough cash to perform the withdrawal transaction (including bank charges and bank charges is 0.50 \$US.)

``````So your condition if(i<bal) is wrong .Imagine the case- pooja has 20 dollar balance in ATM and she want to withdraw xactly 20 dollar.Then atm won't allow pooja to make transaction because  the bank can't charges pooja 0.50 \$US .(So For successful transaction in this cases ,minimum balance should be 20.50 US \$ (as 20\$+0.50 \$ bank charges=20.50\$ .)).But your program allow pooja to make transaction under such case.
``````

So , correct the condition in your code.

``````#include <stdio.h>

int main()
{
int i;
float bal=120;
//printf("Enter the amt to be withdrawed");
scanf("%d",&i);
scanf("%f",&bal);/*You are not taking balance as input*/
if((i%5)==0)
{
if(i+.5<=bal)/*The condition  if(i<bal) was not correct*/
bal=bal-i-0.5;

}
printf("%.2f",bal);
return 0;
}``````
2 Likes

There are two numbers in input X and Y, read the statement again Itâ€™s a bit confusing that Y is always 120.00 in examplesâ€¦ In my input Y is 300.00 (I didnâ€™t have decimal numbers in example, fixed).

Getting WA why?

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