Please find the problem in my program

using namespace std;

int main() {
// your code goes here
int amount_withdrawn;
double total_money;

cin>>amount_withdrawn>>total_money; //input
float par_balance=total_money-amount_withdrawn;  //subtracting 
float balance=par_balance-0.5;

cout<<balance;   //output


return 0;


Share your problem link first :wink:

1 Like

Please use the set precision method to set upto 2 decimal places and the main problem is the third case where the amount being withdrawn is greater than the balance. In that case check both the conditions simultaneously because 300 being multiple of 5 the first loop is being executed and is giving a negative answer. Do refer this code :slight_smile: CodeChef: Practical coding for everyone

thank you

plz check on this input 300 120.00
for this you havenโ€™t check the condition and simply you have done par_balance=total_money-amount_withdrawn;
which will result in 120-300 which is a negetive value and again you have done balance=par_balance-0.5 which will again result in a negetive value
and you have displayed balance

so you need to check first that amount_withdrawn and the charge (0.5) is small enough to be taken out from the total_money