What is the problem in this code for ATM question of easy level ..please help

#include<iostream.h>
#include<conio.h>
#include
int main()
{
int n;
float st,fi;
cin>>n>>st;
if(n>0 && n<=2000)
if(st>=0 && st<=2000)
{
if(n%5==0 && n<st)
fi=st-n-0.50;
else
fi=st;
std::cout << std::fixed;
std::cout << std::setprecision(2)<<fi;
}
getch();
return 0;

}
1 Like

try out this code,after looking at your code i wrote this one in C.

#include<stdio.h>
#include<stdlib.h>
int main()
{
float x,y;
scanf("%f %f",&x,&y);
if ((int)x%5!=0||x+0.50>y)
printf("%.2f",y);
else
{
y=y-x-0.50;
printf("%.2f",y);
}
return 0;
}

you shold use #include instead of #include<iostream.h>
no need to add if(n>0 && n<=2000) and if(st>=0 && st<=2000)
and finally in if(n%5==0 && n<st) it should be (n+0.50<2000)

1 Like

This is accepted code in C.

#include<stdio.h>
int main()
{
int withdraw=0.0;
float amount=0,output=0;
scanf("%d %f",&withdraw,&amount);

if(withdraw%5==0 && amount-0.5>=withdraw)
{
                 output=amount-withdraw-0.5;
}
else
    output=amount;
printf("%.2f",output);
return 0;
}

Please use code tags for posting your code. Also give a brief description of your algorithm, approach. Its easier for people to read and debug your code this way.

1 Like