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

×

atm problem,,I m stucked....help

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        try
        {
        double w=Double.parseDouble(br.readLine());
        double b=Double.parseDouble(br.readLine());
        if(b>w)
        {
            if(w%5==0)
            {
            double a=w+0.50;
            if(b>=a)
                {
                System.out.printf("%.2f",b-w-0.50);
                }
            else 
                {
                System.out.printf("%.2f",b);
                }
            }
            else 
                {
                System.out.printf("%.2f",b);
                }
        }
        else
        {
                System.out.printf("%.2f",b);

        }
        }
        catch(Exception e)
        {
        e.printStackTrace();
      }finally{
        br.close();
      }
    }

}

what's wrong with my answer, why is it giving wrong answer every time?

asked 10 Oct '14, 23:00

urvi_7's gravatar image

0★urvi_7
113
accept rate: 0%

edited 18 Oct '14, 12:50

topcoder_7's gravatar image

2★topcoder_7
2.9k3153

Two things wrong here: 1. There is no such word as "stucked". Please read https://answers.yahoo.com/question/index?qid=20091210084223AA6Jzvo 2. Your algorithm is wrong, you should check if "b > w+0.5". because even if b == w+0.1, the transaction wouldn't happen. Please read my solutions http://www.codechef.com/status/HS08TEST,chefkaushik94, even I had the same problem, its in python so readable

(22 Oct '14, 14:22) chefkaushik942★

Try using \n after every print statement.....

link

answered 15 Oct '14, 23:38

angad_singh95's gravatar image

2★angad_singh95
4026
accept rate: 0%

not necessarily after every printf but your output should totally match the given output in terms of formatting.So take care of that too.

link

answered 16 Oct '14, 06:36

sandeep9's gravatar image

3★sandeep9
4782827
accept rate: 4%

import java.util.Scanner;
 class ATM {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);


        System.out.println("Enter the initial account balance : ");
        double Y = in.nextDouble();


        System.out.println("Enter the amount of cash to withdraw : ");
        double X = in.nextDouble();
        if(X%5 != 0 ){

            System.out.println("Incorrect Withdrawal Amount (not multiple of 5)");
        }
        else{
            if (X>Y ){
                System.out.println(+Y);
            }else{

        double AB = Y-X-0.5;
        System.out.println("Your account balance left is : " +AB);
        }

    }

}
}

My program is also not running

link

answered 16 Oct '14, 07:01

nightfury063's gravatar image

2★nightfury063
1
accept rate: 0%

edited 18 Oct '14, 12:55

topcoder_7's gravatar image

2★topcoder_7
2.9k3153

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
×32
×4

question asked: 10 Oct '14, 23:00

question was seen: 871 times

last updated: 22 Oct '14, 14:22