ATM Problem

#include
using namespace std;
void input(int,double);
void check(int ,double);

int main() 
      {
       int c1;
       double c2;
       cin>>c1>>c2;
       if(c1 > c2 )
       {
        cout<<c2<<endl;
       }
       else
       { 
       input(c1,c2);
     }
   return 0;  
}
     void  input(int c, double d)
     {
         if( (0 < c && c<=2000) && (0<=d && d <= 2000) )
         {
          check(c,d);   
         }  
         else 
         {
         cout<< d<<endl;  
         }
     }
    
      
    void check(int a,double b)
      {
          if(a%5!=0)
          {
           cout<< b<<endl;
          }
          else
          {
            double c;
            c=((b-a)-0.5);
            cout<< c<<endl;
          }
      }

this code compiles perfectly but its shows me wrong answer plsrectify the error in my algorithm

try

50 50

and your solution is not working well for inputs from statement, for example

42 120.00

You also have to check if you have enough money to pay the fee(0.5$).

if initialmoney - moneytodraw > 0.5 and moneytodraw divsible by 5
   do something
2 Likes

#include<stdio.h>
int main(){
float t;float final;int n;
scanf("%d %f",&n,&t);final=t;
if(n<t){
final=(n%5==0)?(t-n-.50):t;}
printf("%.2f",final);
}

#include
#include

using namespace std;

int main()
{
int x;
double y;
cout<<"x : ";
cin>>x;
cout<<"y : ";
cin>>y;
if(x%5==0 && x<=y && x>0 && y>0)
{
y=y-x-0.5;
cout<<fixed<<setprecision(2)<<y;
return 0;
}
cout<<fixed<<setprecision(2)<<y;
return 0;
}

Why is this code wrong?

Try this:

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

correct your answer for 120 120.30. It is giving answer in negative.

Take this for correction. I also did it after 10 attempts although it was quiet easy

Hi, can someone help me with my code? It gives the exact same output but doesn’t seem to be accepted. Here is the link: CodeChef: Practical coding for everyone

Thanks in advance!

#include<stdio.h>
int main() {
float b,c; int a;
scanf("%d%f",&a,&b);
if(a>b) {
printf("%.2f",b);
}
else if(a%5==0) {
c=a+0.50;
b=b-c;
printf("%.2f",b);
}
else if(a%5!=0){
printf("%.2f",b);
}

	return 1;
}

It works well on my computer, but codechef shows Wrong answer. New to this community, so help me out here, and do let me know the mistake I’m making. Thanks in advance :slight_smile:

#include<stdio.h>
int main(){
int x;
float y;
scanf("%d",&x);
scanf("%.2f",&y);
if(y>=0 && y<=20000){
if(x>0 && x<=2000){
if(x<y){
if(x%5==0){

 		if((y-(float)x-0.50)>0)
    		printf("%.2f\n",y-x-0.50);
           }
       else printf("%.2f\n",y);

}

else printf("%.2f\n",y);}}
return 0;
}
// where y code is wrong??

I’m having trouble with this one myself.
A thing I forgot withdraw<credit
also output give a number with single digit after the dot.
I need to get a double digit after the dot

for example: i get 89.5, and it should be 89.50

I recommend you don’t use many fuctions in a short programme, as it’ll be susceptble to many compilation, syntactical or sometimes, very subtle logical errors.
Just take the inputs in the main functions…even if you don’t contraint their values to a maximum of 2000 (but input such), your code will be fine. Then, check the divisibility by 5 and then check whether the balance is greater than the ATM fees (0.5) + the withdrawal amount. If this is true, subtract the amount from balace and output the new balance. The code is much shorter than this one and less confusing.

#include

#include

using namespace std;

int main()

{

int n;

float x,y;

cin>>n;

cin>>x;

if(n%5==0&&n<=x)

{

    y=x-n-0.50;

    cout<<fixed<<setprecision(2)<<y;

}

else

{

    cout<<fixed<<setprecision(2)<<x;

}

}

I am getting correct answer in my pc but it is showing wrong answer in this