HS08TEST - Editorial

Follow standard input/output format. Don’t print those "enter amt … " etc.

import java.util.Scanner;

class Atm{

public static void main(String[] args){

Scanner s=new Scanner(System.in);
double a=s.nextDouble();
double b=s.nextDouble();
if((0<a)&&(0<b)){
    if((a<=2000.0)&&(b<=2000.0)){
        if(a>b) System.out.println(b);
        if((a%5)!=0) System.out.println(b);
        if(((a%5)==0)&&(a==b)) System.out.println(b-a);
        if(((a%5)==0)&&(a<b)) System.out.println((b-a)-0.50);
    }
}

}
}

now also it shows wrong answer! whats wrong now.? output is coming right in my compiler.

Hey @skbly7 -

  1. Q isnt properly closed, common bug when we click on close button twice.

  2. Why close an editorial? People usually come to editorials to ask doubt, so why close it???

#HERE is your answer… your if condition should be if(x+0.5>y)… to know why go to the link…

#HERE is your answer… your if condition should be if(a%5==0 && b+0.5>=a)… to know why go to the link…

whats wrong here? can anyone please tell me.It is showing Wrong answer here.

Common issues:

  • The withdrawal amount is an integer. The account balance is not integer (float, real)
  • To allow withdrawal, the balance must be big enough for the withdrawal AND the fee.
  • The output must display the non-integer balance.

Also: use the Online IDE for testing (if you don’t have any other way to run programs). Don’t submit your code until it has at least run successfully on the examples provided to give the exact same output as shown in the problem. Preferably also run on some other test data that you make up yourself.

1 Like

#include
#include

using namespace std;

int main()
{
int withdrawalAmount;
double currentBalance;
double result = 0;
// cout << “Enter the amount you want to withdraw & your current balance” << endl;
cin >> withdrawalAmount;
cin >> currentBalance;
if (withdrawalAmount % 5 == 0 && withdrawalAmount < currentBalance && currentBalance != 0 && withdrawalAmount != 0)
{
result = (currentBalance - withdrawalAmount) - 0.5;
cout << fixed << setprecision(2) << result << endl;
}
if (withdrawalAmount % 5 != 0)
{
cout << fixed << setprecision(2) << currentBalance << endl;
}
if (withdrawalAmount > currentBalance || withdrawalAmount == currentBalance || withdrawalAmount == 0)
{
cout << fixed << setprecision(2) << currentBalance << endl;
}
return 0;
}

Can you please tell me what is wrong with this code?

take the value of as double precision upto two digits check that also

you have written for success task where is failure task condition and if condition dont add bal+amt

#include
#include
using namespace std;
int main()
{
int x;
float y;
cin>>x>>y;
if((x%5==0) && (y>x+0.5))
{
y=y-x-0.50;
cout<<setprecision(2)<<fixed;
cout<<y;
}
else
{
cout<<setprecision(2)<<fixed;
cout<<y;
}

}

#include <stdio.h>

int main(void) {
int x;
float y,z,a;
scanf("%d %f",&x,&y);
a = (float)x;

if((x%5!=0) || (a>y)){
    printf("%.2f",y);
}
if(x>2000 || x<=0 || y>2000 || y<0){
    printf("%.2f",y);
}

if((x%5==0) && (y>a+0.50)){
    z = y - a - 0.50;
    printf("%.2f",z);
}
return 0;

}

What’s wrong in this code?Please reply.

Can someone tell me whats wrong with this code:
x,y=input().split()
w=float(x)
b=float(y)
if w<b and w%5==0:
r=b-w-0.5
print®
else:
print(b)

#include <stdio.h>

int main(void) {
int wid;
float tot;
scanf("%d",&wid);
scanf("%f",&tot);
if((wid+0.50)<tot)
{
if(wid%5==0)
printf("\n%.2f",(tot-wid-0.50));
}
else
printf("\n%.2f",tot);
// your code goes here
return 0;
}

What is wrong in this code?

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* 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);



}

}

//WHAT IS WRONG IN THIS CODE???

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

#Beginner : ATM
fee = 0.50
amount, total = map(float,input().split())
if amount%5==0 and amount<total+0.50:
print(’%.2f’%(total-amount-fee))
elif amount > total:
print(’%.2f’%total)
elif amount%5 != 0:
print(’%.2f’%total)

It is running perfectly with custom inputs but after submitting it is stated as Wrong answer. Please help me to figure out the issue.

#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
float y;
cin>>x>>y;
if(x>0 && y>=0 && x<=2000 &&y<=2000)
{
if((x%5==0) && (y>=x+0.5))
{
y=y-x-0.50;
cout<<setprecision(2)<<fixed;
cout<<y;
}
else
{
cout<<setprecision(2)<<fixed;
cout<<y;
}
}
}

do else instead of writing all conditons

the input is 120 120.00 and my output is 120.00 but my submission is wrong why?
here is my code:
#include<stdio.h>
#include

using namespace std;
int main()
{
float y,z,w;
int x;
scanf("%d%f",&x,&y);
if(y<=0 || y>2000.00){
cout<<“0.00\n”;
}
else if(x>0 && x%5==0 && x<y){
w =(x+0.50);
z =y-w;
printf("%.2f\n",z);
}
else{
printf("%.2f\n",y);
}

return 0;

}