I have been getting an error in this code every time I run it. Is something wrong with the code? I think I might be facing problems using the custom input maybe.
x = int(input("The amount of cash to be withdrawn: "))
y = int(input("Initial account balance: "))
bank_charges = 0.50
if (x%5 == 0):
y = y - x - bank_charges
print(y)
else:
print(y)
Can anyone help me diagnose the problem here? I know I should be specific with what error I am getting but I change a few things and try again and the error lines changes.
class Codechef
{
public static void main (String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
double balance = scanner.nextDouble();
double result;
if (n % 5 == 0 && n < balance){ result =(balance - n) - 0.5;
System.out.println(result);}
if (n % 5 != 0 && n+0.5<= balance){
System.out.println(balance);}
else if (n>balance || n+0.5>balance){
System.out.println("Insufficient transaction");}
if (x%5==0.00 and x>0 and y>=0 and x<=2000 and y<=2000):
if (float(x)<(y-0.50)):
print(f"{(y - float(x) - 0.50):.2f}",)
else:
print(f"{y:.2f}")
else:
print(f"{y:.2f}")
you look new in competitive programming as you use printf. Its good think to add printf and make your code beautifull but its not needed in competitive programming though.
//variables
int X, Y; // X is need, Y is balance
float fee = 0.5; // bank fee
cin >> X >> Y; // reads and stores X and Y
float fx = X; // turns them into floats
float fy = Y;
if( X%5 == 0)//Checks if need is divisible by 5
{
if( X < Y) // checks if X is less than balance
{
fy -= fx;
fy -= fee;
printf("%.2f", fy); // prints new balance
}
else // if x is greater prints old balance
{
printf( "%.2f", fy);
}
}
else // if x is not divisible by 5, prints out old balance
{
printf( "%.2f", fy);
}
return 0;
}
(This solution was longer than all the ones i saw but it worked well for me, when i kept custom inputs it always worked but once i submitted it it always marked it as wrong. It executes in under 1 second and uses 15.232 kb)