×

# What is wrong with this code for the ATM problem?

 0 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 0★sds1810 1●2●2●4 accept rate: 0% 3.4k●2●19●55

 2 check it with 0 0.00, you'll understand the little mistake you made. :) answered 05 May '12, 17:19 3.4k●2●19●55 accept rate: 20%
 0 budyy check it for 120 120.30. your's giving negative answer. answered 25 Oct '15, 00:03 2★brij_raj 76●7 accept rate: 10%

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

1
accept rate: 0%

 0 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. answered 05 Dec '15, 00:10 1●1 accept rate: 0%
 0 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); } } } answered 09 Dec '15, 00:27 1 accept rate: 0%

# 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?

1
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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