ATM problem C++ help

I have submitted by code 3 times but codechef still says my answer is wrong, I have tested it multiple times and I cannot seem to find whats wrong, if someone could point this out it would really help me:

const double fee = 0.50;
double balance = 0;
int withdraw_amount = 0;




int main()
{
cin >> withdraw_amount >> balance;

if (withdraw_amount % 5 != 0)
	{
		cout << balance << endl;
	}
else if (withdraw_amount > balance)
	{
		cout << balance << endl;
	}
else
	{
		balance -= withdraw_amount + fee;
		cout << setprecision(2) << fixed << balance << endl;
	}



return 0;
}

@az3az09_3134

Brother your code gives WA for test case

 30 30.25
1 Like

you should use && operator to combine the the if and else if statement because here both the conditions need to be followed but not one amongst them.

1 Like

use this code. i got my answer correct.

#include
#include
using namespace std;
int main()
{
float y;
int x;
cin>>x;
cin>>y;
if(x>=0&&x<=2000&&y>=0&&y<=2000)
{ if((x+0.50)<y&&x%5==0)
y=y-x-0.50;
}cout<<y;
}

1 Like

hope this will help you

using namespace std;
int main()
{
int amt, bal ;
cin>>amt;
cin>>bal;
if (amt % 5 == 0)

{

    bal = bal - amt - 0.5;

    cout<<bal;}

else
    cout<<bal;

}