What is wrong with this code for the ATM problem?

Everytime I compile it, I get correct answers. But when I submit it here, it says wrong answer. [http://www.codechef.com/viewsolution/1015864 ]

import java.util.Scanner;
 class ATM
 { 
 	public static void main(String[] args)
 	{
        int wd;
        double ab;
        Scanner sc=new Scanner(System.in);
        wd=sc.nextInt();
        ab=sc.nextDouble();
        if (wd%5==0 && (ab+0.5)>wd)
        {
        	ab=ab-wd-0.5;
        }
        	System.out.printf("%.2f",ab);
    }
 } 

check it with 0 0.00, you’ll understand the little mistake you made. :slight_smile:

2 Likes

mine working file with 0 0.00

int main()
{
    float i2,o;
    int i1;
    scanf("%d%f",&i1,&i2);
    o=i2;
    if((i1%5==0) && (i1<=(i2-0.5)))
        o=i2-i1-0.5;
    printf("%.2f",o);
}

budyy check it for 120 120.30. your’s giving negative answer.

i made the atm code in c
#include<stdio.h>

int main()
{

int i,j;

scanf("%d %d",&i,&j);

if (j>i&&i%5==0){

  printf("%.2f",j-i-0.5);
}

else{
printf("%d",j);
}
return 0;
}

i am getting a wrong answer.
help me please!!

Your condition (ab+0.5)>wd … should be ab >=(wid+0.5)
In your code you have used ab=ab-wd-0.5; which is ab=ab-(wid+0.5); as per the condition.

@raghav_16
In Your condition j>i … you have not considered the bank charges .

Bank Balance >= (Withdrawal Amount + Bank Charges)
what if j>i but j<(i+BANK CHARGES) then also the transaction will not take place.

i have put this code. Everytime it shows a different error. What is the problem with this code?

import java.io.*;

import java.lang.*;

class atm

{

public static void main(String args[])throws IOException

{
InputStreamReader io=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(io);

System.out.println(“Enter your bank balance”);

double bank=Double.parseDouble(br.readLine());

System.out.println(“Enter the amount you want to cash out”);

double amt=Double.parseDouble(br.readLine());

double rem;

if(amt%5==0)

{

rem=bank-(amt+0.5);

System.out.println(“The remaining amount is:”+rem);

}

else

{

System.out.println(bank);

}

}

}

#include<stdio.h>
//#include<conio.h>
//#include<math.h>
int main()
{
long long int t,x;
float y;
scanf("%lld",&t);
while(t–)
{
scanf("%lld",&x);
scanf("%f",&y);
if(x%5==0&&(y-0.5>=x))
{
//cash=cash-out-0.5;
y=y-(x+0.5);
printf("%.2f
",y);
}

else
printf("%.2f

",y);

}

// getche();
return 0;
}
what is wrong with this code anyone can help?