Why this code not showing correct output? www.codechef.com/problems/HS08TEST

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

int main() {
// your code goes here
float in;
int amount;

    cin >> amount>> in;
    
if((in>=0&&in<=2000)&&(amount>0&&amount<=2000))
{
if(amount%5!=0 || amount>in)
      {
      
       cout<<fixed<<setprecision(2)<<in;}
       else{
        cout<<fixed<<setprecision(2)<<((in-amount)-0.50 );
       }
}

return 0;

}

replace your condition with
if(amount%5!=0 || amount>in-0.5)

as if in input, (amount) is equal to (in) then your code will give output of -0.50 which cannot be a value of account balance remaining.

test case for wrong answer of your code
300 300.00

1 Like