What the problem in my ATM solution

Why it show wrong.

#include
using namespace std;

int main() {
// Write C++ code here
float t;
int n;

scanf("%d %f",&n,&t);

if(n > t) printf("%.2f",t);
else if(n % 5 != 0) printf("%.2f",t);
else printf("%.2f", t - (n + 0.5));

return 0;

}

Link : CodeChef: Practical coding for everyone

i have gone through the ATM problem, and one thing i noticed was that it charges a transaction fee of 0.50$ specifically.

now in your first condition :
if(n > t) printf("%.2f",t);

it should be writen as :
float chargefee = 0.50 ; // in this case
if((n+chargefee) > t) printf("%.2f",t);

and thats because there is a possibily of n and t being same.( as n in int)
or maybe ( if n was a float )
possibly,
0.49 less than OR 0.25 less than t
which in case, can trigger the wrong condition.

also i would recommed you to use standard cout and cin for output and input
instead of scanf and printf in c++

2 Likes

and why should i do that. i mean it is mentioned in qustion that input only will be an positive intiger so why worrying about negative intiger

Thank you soo much. It magically worked… You are awesome.
But brother i have one more doubt… You said to use std::cout or std::cin instead of scanf and printf but i read some where to use scanf and printf as they are fast… I am so confused.

this might help :slightly_smiling_face:

1 Like