HS08TEST - Editorial

change that to:

if(x % 5 == 0 and y >= (x + 0.5)):
1 Like

Heres my working solution:

#include <iostream>
using namespace std;

int main() {
int a;
float b;
cin >> a >> b ;

if (a > (b - 0.5)) { cout << b ; }
else if(a % 5 !=0 ) { cout << b; }
else { cout << (b - a - 0.5); } 

return 0;

}

Please Explain why my code is wrong in Custom Input everything is correct but when I submit it says Wrong Answer

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) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
int w = scan.nextInt();
double a = scan.nextDouble();
if(w % 5 == 0 && w <= a){
double ans = a - w;
ans -= 0.50;
System.out.println(
String.format("%.2f", ans));
}
else{
System.out.println(
String.format("%.2f", a));
}

}

}

#include
using namespace std;

int main() {
int x;
float y;
cin>>x;
cin>>y;
if(x%5==0 && x>0 && y>0 && x<=y-0.5){
cout<<((y-x)-0.5)<<endl;
}
else{
cout<<y<<endl;
}
return 0;
}

//Atm Problem

#include

#include<bits/stdc++.h>

using namespace std;

int main() {

int a;

double b;



cin>>a>>b;



if((a % 5 == 0) && (b > (a + 0.50))){

    cout<<fixed<<setprecision(2)(b-a-0.50);

}

else{

    

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

}



return 0;

}

Can anyone help me, what’s the Error in this code?

Isn’t it supposed to be

b >= (a + 0.50) ?
1 Like

Thank you, Code has been successfully submitted.

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

int main() {
#ifndef ONLINE_JUDGE

freopen("input.txt", "r", stdin);

freopen("output.txt", "w", stdout);

#endif

int x;
cin >> x; //withdrawl balance

float y;
cin >> y; //Total balance

float result=0;


if ((x % 5 == 0) && (y<x+0.50) {
	result = y - (x + 0.50);

} else {
	result = y;
}


cout << result << endl;
return 0;

}

please explain why it is giving me wrong answer?

link to solution
ATM Conditional Statement Problem CodeChef HS08TEST codechef - YouTube

#include
using namespace std;

int main() {
int x;
float y;
cin>>x>>y;
if(x%5==0 && x+0.5<y) {
printf("%.2f\n",y-x-0.5);
}
else {
printf("%.2f\n",y);
}
return 0;
}

Hello, what is wrong with this code? I tested a couple of numbers and the results are correct. Thanks!

Consider the test input:

5 5.50
1 Like

You should at least look at previous posts/comments in the discussion.

1 Like
#include <iostream>
using namespace std;

int main(){
    int x; // x -> withdraw; 
    float y; //y -> current ballance
    cin >> x;
    cin >> y;

    if(x>0 && x<=2000 && y>=0 && y<=2000){
        if(x%5 == 0 && (x + 0.50f) < y){ // successful transition
            cout << y-(x + 0.50f); // current amount

        }
        else{ // not a multiple of 5 or x+0.5>=y
            cout << y; // 
        }
    }
    else{
        cout << y;
    }

    return 0;
}

when I am running it with custom input the output is coming correct, but when i am submitting it it’s saying “wrong answer”
it will be a great help you can tell me what i am doing wrong

give the input by yourself

Hi, everyone!
Please tell my why i always get TimeLimit Exeption (0.21sec) when “submit” my code. But when i just “Run” it goes fast (for exmpl 0.06 sec).
Well, even if I try to use best code from solutions, i still get TL (0.21sec)

process.stdin.resume();
process.stdin.setEncoding(‘utf8’);

// your code goes here
process.stdin.on(“data” , (chunk) => {
const input = chunk.split(" ");
const amount = parseInt(input[0]);
const balance = parseInt(input[1]);
const fee = 0.5;
let output = balance;
if(balance >= (amount + fee) && amount % 5 === 0){
output = balance - amount - fee;
}
console.log(output.toFixed(2));
});

#include
using namespace std;

int main() {
int x;
cin>>x;
float y;
cin>>y;
if((x%5==0) && (y>(x+0.50)))
cout<<(y-x-0.50);
else
cout<<y;
return 0;

}

can anyone tell me what’s wrong in this??

You should have checked previous comments before posting your code and ask for help.

1 Like

#include
#include

using namespace std;

int main() {
int with_amount ;
float totalAmount;
cin>>with_amount;
cin>>totalAmount;
if((with_amount>0 && with_amount<=2000)&&(totalAmount>=0 && totalAmount<=2000)){
if (with_amount>=totalAmount){
cout<<fixed<<setprecision(2)<<totalAmount;
}
else if(with_amount%5==0){
totalAmount-=0.5;
cout<<fixed<<setprecision(2)<<totalAmount-with_amount;
}
else if(with_amount%5!=0){
cout<<fixed<<setprecision(2)<<totalAmount;
}
}

return 0;

}

what’s wrong in this code?? :thinking:

You should have gone through the previous comments before posting your query!!

2 Likes

#include
using namespace std;

int main()
{
int withdraw;
float balance;
cin>>withdraw;
cin>>balance;
if((withdraw % 5 == 0) && (withdraw + 0.50) < balance)
printf("%.2f",balance - withdraw - 0.50);
else
printf("%0.2f", balance);
return 0;
}

why this code is wrong??