#include
int main()
{
int amt;
float balance;
std::cin>>amt>>balance;
if (amt%5!=0)
{
std::cout<<balance;
}
else if (amt%5==0&&amt<balance)
{
balance=balance-amt-0.5;
std::cout<<balance;
}
else if (amt>=balance)
{
std::cout<<balance;
}
return 0;
}
wHAT IS WRONG IN ABOVE PROBLEM?
1 Like
There are a couple of errors in your code.
(1).The condition (amt%5==0 && amt< balance) is incorrect.
Read the following line in problem statement:
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.
That means for successful transaction , (amount pooja wants to withdraw+ the bank service charge <=Current balance in Pooja’s Account)
You are not considering the bank-charge.
So correct the above condition as:
else if ((amt%5==0) && (amt+.5)<=balance)
(2)Also ,your code is missing else condition
Your code prints nothing when the three condition does not hold.
This is wrong ,youshould print the balance under such circumstances .
Please Read the problem statement again.
if (amt%5!=0)
{
std::cout<<balance;
}
else if (amt%5==0&&amt+.5<=balance)
{
balance=balance-amt-0.5;
std::cout<<balance;
}
else if (amt>=balance)
{
std::cout<<balance;
}
else
{
std::cout<<balance;
}
3 Likes
#include<stdio.h>
int main()
{
int x;
float y;
printf(“Input\n”);
scanf("%d %f",&x,&y);
if(x>0 && x<=2000 && y>=0 && y<=2000 && y-x-0.5>=0 && x%5==0)
y=y-x-0.50;
printf(“Output\n”);
printf("%f",y);
return 0;
}
WHAT WRONG IN THIS
CodeChef: Practical coding for everyone here is my solution
and you are getting a WA because your code is missing some corner conditions
3 Likes