HS08TEST - Editorial

You have taken everything as float. It is mentioned in Question that the amount to withdraw is an integer.

can someone tell me what is wrong with this code

import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
double y = sc.nextDouble();
if(x%5 == 0 && x<y-0.5)
{
y = y-x-0.5;
System.out.print(y+“0”);
}
else
{
System.out.print(y+“0”);
}
}
}

you have to give output with two digits of precision, and value of x and y should be from 0 to 2000

What is wrong with this code?
Am I making some silly mistake? Let me know soon!
#include
#include
using namespace std;
int main()
{
int x;
float y;
cin>>x>>y;
if((x>0&&x<=2000)&&(y>=0&&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;
}
}
return 0;
}

WHERE DID I GO WRONG
#include<bits/stdc++.h>
using namespace std;
int main()
{
double init,out=0,bal=0;
int amt;
cin>> amt;
cin>> init;
if(init<=2000)
{
if(amt<=init)
{
if(amt%5==0)
{
out=amt+0.50;
bal=init-out;
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << bal;
}
else
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << init;
}
}
else
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << init;
}
}
return 0;
}

#include <stdio.h>

int main(void) {
// your code goes here
int x ;
float bal,rem;
scanf("%f",&bal);
scanf("%d",&x);
if((x%5 != 0 )|| ((x+0.50)>bal))
{
printf("%0.2f",bal);
}
else
{
rem = bal-(x+0.50);
printf("%0.2f",rem);
}
return 0;
}

can anyone help me whats wrong with this code

#include <stdio.h>

int main(void)
{
double ini,op;
int tamt,amt;
scanf("%d\t",&amt);
scanf("%f\n",&ini);
tamt=amt+0.5;

if((tamt>ini) || amt%5!=0)
    printf("%.2f",ini);
else
{
    op=ini-tamt;
    printf("%.2f",op);
}
return 0;

}

can anyone tell why is this wrong

Use BufferedReader instead of Scanner and also use String.format() or System.out.printf() method instead of directly adding “0” to y.

#include
#include
using namespace std;

int main() {
	// your code goes here
	int x;
	float y;
	cin>>x>>y;
	if(x>0&&x<2000 && y>0&&y<2000)
{
	if(x>y || x%5 != 0)
	{
	    cout << std::fixed;
        cout << std::setprecision(2);
	    cout<<y<<endl;
	}
	if(x%5==0 && (x+0.5)<y)
	{
	    cout << std::fixed;
        cout << std::setprecision(2);
	    cout<<float(y-x-0.50)<<endl;
	}
}
	return 0;
}

whats 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 atm(int amount , double balance){

    double charges = 0.50;
    
    double res = 0.00;
    
    if (amount % 5  == 0){
        
        if(balance >= amount){
            
            res = balance - amount - charges;
            
           System.out.println(res);
        }
        else{
           System.out.println(balance);
            
        }
    }
   
    else{
        
    
           System.out.println(balance);
       
        
       
    }
    
}



public static void main (String[] args) throws java.lang.Exception
{   
             Scanner sc = new Scanner(System.in);
	int amount = sc.nextInt();
	double balance = sc.nextDouble();
	
	atm(amount,balance);
	
	
	
	
	
}

}

whats wrong with this code?after clicking on submission button it is saying wrong code…Why?

#include<bits/stdc++.h>
using namespace std;

int main()
{

int x;
float y;
cin >> x ;
cin >> y;
if ((x<=2000 && x>0) && (y<=2000.00 && y>0.00))
{
if ((y>(x+0.50)) && x%5==0)
{
float final=(y-(x+0.50));
cout << fixed << setprecision(2)<<final;
}
else{
cout <<fixed<<setprecision(2)<<y;
}
}
return 0;
}

what’s wrong here??

#include
using namespace std;
int main() {
int x;
double y,r=0.00;
cin >> x;
cin >>y;
if(y>(x+0.50) && x%5==0){
r=y-x-0.50;
printf("%0.2f",r) ;
}
else {
printf("%0.2f",y);
}
return 0;
}
please tell me why it’s showing wrong status ??
it is running successfully , so why ?

#include<bits/stdc++.h>
using namespace std;

int main() {
int amt;
double bal;
cin>>amt;
cin>>bal;
if(amt>bal)
cout<<bal;
else if(amt%5==0&&(amt+0.5)<bal)
{

    cout<<fixed<<setprecision(2)<<bal-amt-0.5;
}
else
{
    cout<<fixed<<setprecision(2)<<bal;
}

}

what is the problem in this solution??

what is wrong in this? The output is correct in vsc but it still says wrong answer.

    #include <stdio.h>

    int main()

    {

        int wa;

        float bal;

        scanf("%d%f", &wa, &bal);

        if ((wa % 5 == 0) && (bal > (wa + 0.5)))

        {

            printf("%.2f", bal - (wa + 0.5));

        }

    }

Hi,

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.

Got no idea WTH it’s not submitting. PLS help.

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");}

}
}

Suppose the input is 120 120.00 then your code gives the output -0.50. Check for that case also. Answer for this case should be 120.00

#include
#include
using namespace std;

int main() {
// your code goes here
unsigned int am;
float bal;
cin>>am;
cin>>bal;
if(0<am&&am<=2000&&0<=bal&&bal<=2000)
{
if(am<bal&&am%5==0)
{bal=bal-am-0.50;
cout<<setprecision(2)<<fixed<<bal<<endl;
}
else if((am+0.5)<=bal)
{bal=bal-am-0.5;
cout<<setprecision(2)<<fixed<<bal<<endl;
}
else
cout<<setprecision(2)<<fixed<<bal<<endl;

}
return 0;

}

It is giving correct output but while submitting it is showing wrong answer. please tell me what is the issue related to it.

#include <stdio.h>

int main()
{
const float charge = .5;
float balance = 0;
int withdraw = 0;
int check = 0;

scanf("%d %f", &withdraw, &balance);

if (withdraw % 5 == 0)
	check = 1;

if (withdraw <= balance && check && balance >= 5.5)
	balance = balance - (withdraw + charge);

printf("%.2f", balance);

return 0;

}

I get the right inputs but when I try to submit it the programs say I get the wrong solution and I don’t know why.

To all the people facing issues with NZEC, or nullPointer.
Try adding a check for null input like below.
Apparently the testing run passes null input.

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String inpt = br.readLine();
	if (null != inpt) {
		String[] inptArr = inpt.split(" ");
		int X = Integer.parseInt(inptArr[0]);
		double Y = Double.parseDouble(inptArr[1]);

		if ((X + 0.50) < Y && X % 5 == 0)
			Y = Y - (X + 0.50);

		System.out.printf("%.2f", Y);
	}
	br.close();
}