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

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

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.