https://www.codechef.com/problems/HS08TEST

Whenever run this code i get wrong answer can someone help me in notifying the error:
code:
#include
#include
using namespace std;
int main()
{
int x,i;
float bal;
cout<<"\nEnter the balance amount";
cin>>bal;
cout<<"\nEnter withdraw amount";
cin>>x;
if(x%5==0 && x+0.5<bal)
{
bal=bal-x-0.50;
cout<<setprecision(2)<<bal;
}
else
cout<<setprecision(2)<<bal;
return 0;
}

1 Like

you used unnecessary
cout<<"\nEnter the balance amount";
cout<<"\nEnter withdraw amount";
which are not present in output.

you have taken variable x at place of bal.

and you didnot used fixed before setprecision(2).

hopefully you understand why you got WA.

1 Like

don’t put the unnecessary thing in your output. Not even newline before output.