ATM: Getting wa

What’s wrong with this code. Getting WA.

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float bal,final;
int trans;
cin>>trans>>bal;
int a=trans,c;
c=trans%5;
if(c==0 && bal>trans && bal<=2000.00 && trans<=2000 && trans>=0 && bal>=0.00)
{
final=bal-trans-0.50;
cout<<setprecision(2)<<fixed<<final<<"\n";
}
else
cout<<setprecision(2)<<fixed<<bal<<"\n";
return 0;
}

WA does not mean there is an exception in your code. Your code may have failed to pass the test cases that the judge uses. Check out the FAQ for WA here

1 Like

Hi you are missing a couple of condition in your code(Important codition you were missing is bal>trans+0.50 (Its not bal>trans))::
This is the corrected code and i am sure it will get accepted::

   #include<iostream>
   #include<iomanip>
   using namespace std;
   int main()
   {
        float bal,final;
        int trans;
        cin>>trans>>bal;
        int a=trans,c;
        c=trans%5;
        if(c==0 && bal>trans+0.5 && bal<=2000 && trans<=2000.00 && trans>0 && bal>=0.00)
        {
          final=(bal-trans)-0.50;
          cout<<setprecision(2)<<fixed<<final<<"\n";
        }
       else
       cout<<setprecision(2)<<fixed<<bal<<"\n";
       return 0;
  }
2 Likes