HS08TEST - Editorial

Don’t Use new line after displaying the answer.
My Code :-

#include< iostream>
#include< iomanip>
using namespace std;

int main(void)
{

float y,z;int x;
cin>>x>>y;
cout<< fixed<< setprecision(2);
if(x>0 && x<=2000 && y>=0 && y<=2000){
if(x>=y)
cout<< y;
else if(x<=y-0.5)
{
if(x%5==0)
cout<< y-x-0.50;
else
cout<< y;
}
else cout<< y;
}
return 0;
}

Enjoy bro

import java.util.Scanner;
import java.text.DecimalFormat;
public class Main
{
public static void main(String args[])
{
double withdraw,balance;
Scanner sc=new Scanner(System.in);
withdraw=sc.nextDouble();
balance=sc.nextDouble();
if((withdraw%5==0) && (balance>=(withdraw+0.05f)))
System.out.println(new DecimalFormat(“0.00”).format(balance-withdraw-0.05f));
else
System.out.println(new DecimalFormat(“0.00”).format(balance));
}
}

#include<stdio.h>
float a,b,c;
int mul(float n);
int main(){
scanf("%f %f",&a,&b);
if(a<=b){
if(mul(a)){
c = b - a - 0.5;
printf("%.2f",c);
}

}

if(!mul(a))
printf("%.2f",b);

if(a>b)
    printf("%.2f",b);

}
int mul(float n){
while(n>0.0)
n=n-5.0;

if(n==0.0)
return 1;
else
return 0;

}

can anyone tell, why it is showing wrong answer

What is wrong in this code of mine ?

#include <iomanip>
#include <iostream>

int main()
{
	int x;
	float y;
	std::cin >> x >> y;

	if ((x % 5 == 0) && (x + 0.50 <= y))
	{
		if (0 < x && x <= 2000 && 0 <= y && y <= 2000)
		{
			float j = y - x - 0.50;
			std::cout << std::setprecision(2) << std::fixed << j;
		}
	}
	else
	{
		std::cout << std::setprecision(2) << std::fixed << y;
	}
	return 0;
}

#include
#include
using namespace std;

int main(){
    int witha;
    float balanb;
    cin >> witha;
    cin >> balanb;
    if (witha< balanb){
        if(witha%5==0){
            balanb= balanb-witha-0.5;
            cout << balanb;
        }
        else {
            cout<< balanb;
        }
    }
    else{
        cout << balanb;
    }
    return 0;

}

Whats the error??

How to start with the python. I am begining to the python but i am getting error? so Kindly reply me.

  • #include <stdio.h>
    #include <stdlib.h>

    int main() { int a=0; float
    b=0;

    scanf("%d %f",&a,&b);
    

    if(a<b){
    if(a%5==0){
    printf("%.2f\n",(b-a)-0.50);
    }
    else{
    printf("%.2f\n",b);
    } } else{
    printf("%.2f\n",b);
    }
    return 0; }

Why is wrong ?

#include
#include
#include<stdlib.h>
using namespace std;

int main()
{

int withdrw;

float max_bal,bal;

cin>>withdrw;

cin>>max_bal;

if((withdrw>0)&&(withdrw<2000)){

if((max_bal>0)&&(max_bal<2000))

{
if(withdrw<max_bal)

{

if(withdrw%5==0){

bal=max_bal-withdrw;

bal=bal-0.50;

cout<<setprecision(2)<<fixed<<bal;

}

else

{

bal=max_bal;

cout<<setprecision(2)<<fixed<<bal;

}

}

else

{

bal=max_bal;

cout<<setprecision(2)<<fixed<<bal;

}

}

}

else

{

exit(0);

}

return 0;

}

what is the problem in this code

#include<stdio.h>
main()
{
int a;
float b;
scanf("%d",&a);
scanf("%f",&b);
if(a>0 && a<=2000 && b>0 && b<=2000)
{

	if(a%5==0)
		{
			if( b>=(a+.50))
			{
			b=b-a-0.5;
			printf("%0.2f",b);
			}
			if(b< a+.5)
			printf("%0.2f",b);
		}
	else
	printf("%0.2f",b);

}

}

What is wrong with this code?

#include<stdio.h>
int main(){
unsigned int amt;
float atm=0.5,bal,rlt;
scanf("%u %f",&amt,&bal);
if((bal+atm)>=amt && amt%5==0 && (0<=bal<=2000) && (0<amt<=2000))
rlt=bal-(amt+atm);
printf("\n%.2f",rlt);
return 0;
}
whats wrong in my code

amnt ,bal = [float(x) for x in input().split()]
print(bal,amnt)
if(amnt > 0 and bal > 0):
if(amnt <= 2000.00 and bal <= 2000.00):
if(amnt+0.5 <= bal and amnt%5 == 0 ):
print(format(bal-amnt-0.50,".2f"))
else:
print(format(bal,".2f"))
whats wrong in this

#include <stdio.h>
#include <stdlib.h>

int main()
{
int transaction;
double balance, response, charges;
balance=2000;
charges=0.50;
printf("\n ATM Machine");
printf("\n------------------");
printf("\n1 Enter the Saving Account");
printf("\n2 Enter the Withdraw money");
printf("\n3 Quit");
printf("\nEnter your Selection:");
scanf("%lf", &response);
if(response==1)
{
printf("\n---------------------");
printf("\nYour current balance: %0.2lf", balance); printf("\n---------------------"); printf("\nThank you\n"); } if(response==2) { printf("\nEnter amount to withdraw:"); scanf("%d", &transaction); if((transaction)%5==0) { printf("\n---------------------"); printf("\nYour current balance: %0.2lf", balance-transaction-charges);
printf("\n---------------------");
printf("\nThank you for Transaction\n");
}
else
{
printf("\nTransaction Failed");
}
}
if(response==3)
{
printf("\nThank you\n");
}

return 0;

}

Brother, check this code. And tell me what’s wrong on it.

#include <stdio.h>
int main(){
unsigned int amount;
float balance;
scanf ("%d %f",&amount,&balance);
if (balance>=0 && balance <=2000){
if (amount<=(balance-0.5) && amount>0){
if(amount%5==0)
printf("%f",(balance-amount)-0.5);
}
}
return 0;
}

what is the error here? please help me

import java.util.Scanner;
import java.text.DecimalFormat;
class Atm{

public static void main(String[] args){

Scanner s=new Scanner(System.in);
System.out.println("enter amt to be withdrawn:");
double a=s.nextDouble();
System.out.println("enter the current amount in account");
double b=s.nextDouble();
DecimalFormat df=new DecimalFormat("#### 0.00");
if((0<a)&&(0<b)){
    if((a<=2000.00)&&(b<=2000.00)){
        if(a>b)
	 System.out.println(df.format(b));
        if((a%5)!=0)
	 System.out.println(df.format(b));
        if(((a%5)==0)&&(a==b)) 
	System.out.println(df.format(b-a));
        if(((a%5)==0)&&(a<b)) 
	System.out.println(df.format((b-a)-0.50));
    }
}

}
}

How to get input in python? Example for python here in forum doesn’t work like:

wd_amt,in_amt = list(map(float, input().split()))

Editorialist solution is wrong withdraw%5==0&&balance>=withdraw+0.5 is the correct condition…

2 Likes

You dont need those printf() statements you have added in your code. There’s no need of that, go by the I/O format specified in the problem!!

2 Likes

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

do paste your code with proper identation.

if((x%5==0)&&(x<y))-This is faulty, as y should be greater than x+0.5, as problem clearly says "enough cash to perform the withdrawal transaction (including bank charges). "

Make changes and get back to me in case of discrepancy :slight_smile: