for beginners question ATM, I am getting wrong answer for this code.

#include
using namespace std;
int main()
{
int a;
float b,c;
cin>>a;
cin>>c;
if((0<a<2000)&&(0.0<c<2000.0))
{
if ((a<c)&(a%5==0))
{
b=c-a-0.5;
cout<<b;
}
else
{
b=c;
cout<<b;
}
}
return 0;
}

Check your input for-

120 120.00

If it prints -0.5 , i think you get the whats wrong in logic.

the output for 120 120.0 is 120, as demanded in the problem, um thats not problem
something else

Try this test case then, if 120 120 isnt the failing case then this must be.

Input
119.9 120

Correct output is 120.00

@vijju according to the problem the first number is an integer and second one is a real number. So a better test case would be this :-

Input: 120 120.25

Correct Output: 120.25

1 Like

Yes you are right. The point was just that, when the values are very close. 120 and 120.1 should also do. Thanks for pointing that out, i will keep it in mind next time :slight_smile:

1 Like
//