Practice Beginner Level - ATM challenge

This is first attempt on the codeChef. Can someone please help me to understand what is wrong with my code here? It seems to be working fine on my IDE and on Custom Input. Kindly suggest.

Code:

class Main{
float x = 0;
int y = 0, calc = 0;
int max = 1999;
int min = 1;

	int bank_amt = (int) ((Math.random() * ((max-min)+1)) + min);
	System.out.println("Input: ");
	Scanner in = new Scanner(System.in);
	int withdrawal_amt =in.nextInt();
	System.out.print(bank_amt + "\n");
	
	if((withdrawal_amt > 1) && (withdrawal_amt < 2000)) {
		calc = withdrawal_amt % 5;
		if(calc == 0) {
			 y = bank_amt - withdrawal_amt;
			 x = (float) (y - 0.50);
		}
		else {
			x = bank_amt;
		}
		System.out.println("Output: " +x);
	}else {
		System.out.println("Output: " +bank_amt);
	}

Can you post the link to your solution ?

https://www.codechef.com/submit/HS08TEST … Thanks

Someone really needs to make a “[Tutorial] Link to the Code!” thread to go along with @syntaxhacker’s [Tutorial] CoLoR format the Code! - it’s amazing how often people get it wrong :slight_smile:

2 Likes

I don’t know much Java but why is there Math.random() in your code?

As per the ATM question, there should also be an amount in the user’s bank account which should not exceed more than 2000. So I am just randomly generating numbers between 1-1999.

Don’t randomly generate the bank amount. Take it in as an input.
See this for more info. https://www.youtube.com/watch?v=gaPdjwuFZTs

1 Like