/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args)
{
// your code goes here
int x ,y=150;
System.out.println("enter the withdrawal amount = ");
Scanner s=new Scanner(System.in);
x=s.nextInt();
double z;
if (x % 5 == 0 &&x<=y)
{z=y-x+0.50;
System.out.println("balace remaining"+z);
}
else if(x%5!=0)
System.out.println("non multiple of 5"+y);
else if(x%5==0&&x>y)
System.out.println("insufficient balance"+y);
}
First thing …(using namespace std; ) will solve the iostream inclusion issue.
second fault in code is at certain test case …cout or remaining balance is negative .For eg 120 120.4 wil give -0.5 which is wrong . So add one more condition in if statement ie ( withdrawl +0.5)<=currentBalance
third just a suggestion,avoid using x and y, give useful names
def atm(num1, num2):
y = int(num1)
z = float(num2)
lastdig = int(repr(y)[-1])
if y>z or y==z:
return(format(z, ‘.2f’))
else:
if lastdig == 0 or lastdig==5:
m = float(z-y-0.50)
return(format(m, ‘.2f’))
elif lastdig != 0 or lastdig != 5:
return(format(z, '.2f'))
I wrote this Python code and when I submit it, it states that it is wrong but whenever I run it on my computer or on the codechef IDLE it works very well