HS08TEST - Editorial

#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;

}

what is wrong in 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;

}

Double declaration of k

Float amt not atm

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'))

moneydraw, moneyin = input("").split()
print(atm(moneydraw, moneyin))

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

#include <stdio.h>

int main(void) {
int x;
float a;
scanf("%d",&x);
scanf("%f",&a);
if(x>0 && x<=2000)
{ if(x%5==0 && x<=a)
{
a=a-x-.5;
printf("%.2f",a);
}
else if (x%5!=0 || (x+0.5)>a)
printf("%.2f",a);
}
return 0;
}
what is wrong with my code?

there would be -0.5 not +0.5

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

but it shows wrong ans??

use bufferedreader instead of scanner

yes

That was asked 5 years ago

1 Like

cook your dish he

amount=0
balance=0
inp=’’
try:
inp=input()
if len(inp)!=0 and len(inp.strip())!=0:
amount, balance = inp.split(" “)
except Exception as e:
pass
amount = int(amount)
balance = int(balance)
if 0<=amount<=2000 and 0<=balance<=2000:
print(amount,end=” “)
print(balance)
if amount%5==0 and amount+0.5<balance:
balance=balance-amount
balance=balance-0.5
else:
balance=0
print(”{:.2f}".format(balance))

why i’m getting wrong answer when i submit,i tested all possible cases and fixed errors