 # Help me to solve the error

you should use if and then else or else if …not two ifs

#include <stdio.h>
int main ()
{
float Y;
int X;
scanf("%d %f",&X,&Y);
if ((X>0&&X<=2000)&&(Y>=0&&Y<=2000))
{

``````    if (X>Y)
{
printf("%.2f\n",Y);

}
else if (X%5==0)
{
float balance;
balance = Y-X-0.50;
printf("%.2f\n",balance);
}
else
{
printf("%.2f\n",Y);
}
}
return 0;
``````

}

anyone plz tell me what is wrong in this code

kartheek2159
what is this code for??

Pooja would like to withdraw X \$US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja’s account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 \$US. Calculate Pooja’s account balance after an attempted transaction

else if((X%5==0) &&(y>=(x+0.5))

You didn’t check the case for insufficient balance

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of =the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int amt=sc.nextInt();
double bal=sc.nextDouble();
if(amt%5==0 && amt<=(bal-0.5))
System.out.format("%.2f",((bal-0.5)-amt));
else
System.out.format("%.2f",bal);
}
}

(initial_bal>=(withdrawl_amt+0.5)))
Try using
(greater then or equals to)
in the if condition

1 Like

#include
#include <math.h>
using namespace std;

int main()
{
int x;
float b,a = 120;
cout << “enter amont to withdraw” << endl;
cin >> x;
b = ((a - x) - 0.50);
if (x % 5 == 0)
{
if (x + 0.50 < a)
{
cout << "amount you entered " << x << endl;
cout << "remaining amount in your account " << b << endl;
}
else
{
cout << "insufficient balance " << endl;
cout << "account balance " << a << endl;
}
}
else
{
cout << "enter correct amount " << endl;

``````    cout << "account balance " << a << endl;
}
return 0;
``````

}
can you please tell me what is wrong with this code?

1 Like

Even if i did that,
look at the code i have…
#include
#include

using namespace std;

int main()
{
int x;
cin>>x;
float y;
cin>>y;
if(x%5==0)
{ float a= x;
int z= y;
if(z>x)
{
float b= y-(a+0.50);
cout<<setprecision(2)<<fixed<<b<<endl;
}
else if(x>z)
{
cout<<setprecision(2)<<fixed<<y<<endl;
}
}
else if(x%5!=0)
{
cout<<setprecision(2)<<fixed<<y<<endl;
}
return 0;
}

still its showing error

Consider the test input:

``````5 5.50
``````

did,but it gave me output of 0.00,yet my answer is poping up to be wrong.

Link to updated solution? The one you posted in help me to solve the error. - #19 by geeky_boy gives no output for that test input on my machine. (Edit: though it does give the correct output on Codechef. Interesting.)

Edit:

if it’s this one, consider the test input:

``````5 5.49
``````

Can someone show me what mistake did I make here?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
double y;
cin>>x;
cin>>y;

``````if((x%5==0) && (x+0.5<y))
{
double bal=y-(x+0.5);
cout<<fixed<<setprecision(2)<<bal;
}
else{
cout<<fixed<<setprecision(2)<<y;
}
``````

return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()

{

``````int x;

double y;

cin>>x;

cin>>y;

if((x%5==0) && (x+0.5<=y))

{

double bal=y-(x+0.5);

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

}

else{

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

}
``````

return 0;

}
Now? Changed the condition

Should work now, I think.

1 Like

#include
using namespace std;
int main() {
int x;
float y;
cin>>x>>y;
if(x % 5 == 0 && x<=y -0.5)
y=y-x-0.5;
if(x % 5 !== 0 && x<=y -0.5)
y=y;
else
y=y;
cout<<y;
return 0;
}
what is wrong in this code?

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! where am i missing things can anybody help me plz
#include
#include
using namespace std;
int main() {
int withdraw;
float totalamt;
cout<<"\nEnter the amount to be withdraw : “;
cin>>withdraw;
cout<<”\nEnter the total amount in your account : “;
cin>>totalamt;
if(totalamt>withdraw && withdraw%5==0)
{
cout<<”\nTransaction completed"<<endl;
totalamt=totalamt-withdraw-0.50;
}
else
{
cout<<“transaction cancled”<<endl;
}
cout<<"Total Balance of your account is : "<<fixed<<setprecision(2)<<totalamt;
return 0;
}