help me to solve the error.

guys this is the problem with my code written below. plz help me to solve the error

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.

Input
Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.

Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja’s initial account balance.

Output
Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.

CODE

#include<stdio.h>
int main()
{
int withdrawl_amt;
float initial_bal;
scanf("%d,%f",&withdrawl_amt,&initial_bal); 
if(withdrawl_amt %5==0 &&(initial_bal>(withdrawl_amt+0.5)))
{
printf("%.2f",(initial_bal-(withdrawl_amt+0.5)));
}
else
{
printf("%.2f",initial_bal);
}
return 0;
}

scanf("%d,%f",&withdrawl_amt,&initial_bal);

Remove comma in between %d and %f,it should be like this scanf("%d %f",&withdrawl_amt,&initial_bal);

3 Likes

Yes, the comma is the issue.

1 Like

Please let me know whats wrog with this

x = input(" “)
y = input(” ")
if(int(x)%5==0):
if(x<y):
print(round((y-x-0.5),2))
else:
print(y)

How do we round of a decimal value to 2 decimals in c++?

for 2 decimal round off using printf() —>

printf("%.2f", value);

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

2 Likes

Pls tell me what is wrong with this code?

/* package codechef; // don’t place package name! */

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
{
// your code goes here
Scanner sc= new Scanner(System.in);
double x,y;
x=sc.nextDouble();
y=sc.nextDouble();
if(x<=(y-0.50) && x%5==0)
System.out.println(y-x-0.50);
if(y<x)
System.out.println(y);
}
}

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

https://www.codechef.com/problems/HS08TEST

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?

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.