You are not logged in. Please login at www.codechef.com to post your questions!

×

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);
    }
 }

asked 05 May '12, 14:59

sds1810's gravatar image

0★sds1810
1224
accept rate: 0%

edited 05 May '12, 17:15

cyberax's gravatar image

3★cyberax ♦
3.4k21955


check it with 0 0.00, you'll understand the little mistake you made. :)

link

answered 05 May '12, 17:19

cyberax's gravatar image

3★cyberax ♦
3.4k21955
accept rate: 20%

Answer is hidden as author is suspended. Click here to view.

answered 05 May '12, 21:42

deathholes's gravatar image

0★deathholes
(suspended)
accept rate: 0%

edited 06 May '12, 16:45

cyberax's gravatar image

3★cyberax ♦
3.4k21955

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

link

answered 25 Oct '15, 00:03

brij_raj's gravatar image

2★brij_raj
767
accept rate: 10%

edited 25 Oct '15, 00:04

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!!

link

answered 04 Dec '15, 23:19

raghav_16's gravatar image

0★raghav_16
1
accept rate: 0%

edited 04 Dec '15, 23:20

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.

link

answered 05 Dec '15, 00:10

aniketripathi's gravatar image

2★aniketripathi
11
accept rate: 0%

edited 05 Dec '15, 00:20

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);

}

}

}

link

answered 09 Dec '15, 00:27

abhaygoyal's gravatar image

0★abhaygoyal
1
accept rate: 0%

edited 09 Dec '15, 00:29

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\n",y); }

else
printf("%.2f\n",y);


}

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

link

answered 17 Jun '17, 18:53

walker002's gravatar image

1★walker002
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×190

question asked: 05 May '12, 14:59

question was seen: 1,737 times

last updated: 17 Jun '17, 18:53