ATM Problem: Wrong Answer

#include
using namespace std;
int main(void){
float w;
float b;
cin>>w>>b;
if (int(w)%5 == 0)
{
if (b>=w)
{
cout<<b-w-0.5;
}
else
{
cout << b;
}
}
else
{
cout << b;
}
}

Right Output. Wrong Answer. Help?

Are you sure it gives correct output ?
Check your output for : 100 100
As it seems to me it will show -0.5, which is ofcourse wrong.

2 Likes

here in the second if statement ‘b’ cannot be greater than or equal to w since bank also has to charge 0.50$ therefore it should be if (b>w+0.50).
you should declare the ‘w’ as an integer type.
and to make your program more compact you can make use of logical and (&&)operator instead of 2 if’s

1 Like