ATM C++ Keep getting wrong answer

I keep getting the wrong answer and I don’t know why.

#include
using namespace std;
int main(int argc, const char * argv[])
{

const float fee = 0.50;
unsigned int widthdrawl = 0.00;
float balance = 0.00;

cout << "Enter widthdrawl amount and bank balance ex[30 120]" << endl;
cout.precision(4);
cin >> widthdrawl;
cin >> balance;

while(balance > 0){
    if((widthdrawl + fee) > balance) {
        cout << balance << endl;
        cout << "Not enough money in account" << endl;
        break;
    }
    
    else if(widthdrawl % 5 != 0) {
        cout << balance << endl;
        cout << "Did not enter a multiple of 5" << endl;
        break;
    }
    
    else if((widthdrawl % 5 == 0)) {
        balance = balance - widthdrawl - fee;
        cout << balance << endl;
        break;
    }
    
}

return 0;

}

Blockquote

Hi, @tyrthor
In your code i just removed some comments and changed the “cout.precision(4);” to “cout.precision(6);” and it got accepted.
In codechef always keep your precision to greater than equal to 6 or as per given in the question.
link to the accepted solution

1 Like

#include
#include
#include<stdlib.h>

using namespace std;
main()
{
float balance;
int amount;
cin>>amount;
cin>>balance;
int r=(amount%5);
if(amount >0 && amount<=2000 && balance>=0.00 && balance<=2000.00 )
{
if(balance>amount && r==0)
{

    cout<<fixed<<setprecision(2)<<(balance-amount-0.50);
    }else

if(amount >balance || r!=0 )
{
     cout<<fixed<<setprecision(2)<<balance;
}
}
return 0;

}

What’s wrong with this code.
Why it’s continuously showing “wrong answer”.

Please Help!!

#include
#include
#include<stdlib.h>

using namespace std;
main()
{
float balance;
int amount;
cin>>amount;
cin>>balance;
int r=(amount%5);
if(amount >0 && amount<=2000 && balance>=0.00 && balance<=2000.00 )
{
if(balance>amount && r==0)
{

    cout<<fixed<<setprecision(2)<<(balance-amount-0.50);
    }else

if(amount >balance || r!=0 )
{
     cout<<fixed<<setprecision(2)<<balance;
}
}
return 0;

}

//