HS08TEST - Editorial

Sirs,
I’m new here. Would you please let me know why this code gives a wrong answer?

#include
using namespace std;
int main(){
double bal, withdraw;
cin>>bal>>withdraw;
if (((int)withdraw%5)!=0) cout<<bal;
if ((int)withdraw%5==0){
if(bal-withdraw-0.5>0){
cout<<bal-(withdraw+0.50)};
else cout<<bal;
}
return 0;
}

@mnm_bazinga

declare the variable withraw as int data type.

include

include

using namespace std;
int main()
{ int a,b;
cin>>a>>b;
if(a%5==0 && a<b)
{std::cout << std::fixed;
std::cout << std::setprecision(2)<<(b-a-0.50);}

else if(a%5!=0)
{std::cout << std::fixed;
std::cout << std::setprecision(2)<<b;}
else if(a>b)

{std::cout << std::fixed;
std::cout << std::setprecision(2)<<b;}return 0;}

include

include

using namespace std;
int main()
{
int x;
float z=0.5;
float y;
float total;
cin>>x;
cin>>y;
if(x>0&&x<=2000&&y>=0&&y<=2000){
if(x%5==0&&x<y)
total=y-x-z;
else if(x%5!=0&&x<y)
total=y;
else if(x%5==0&&x>y)
total=y;
else if(x%5==0&&x==y)
total=y;
cout<<setprecision(2)<<fixed<<total;}
return 0;
}
What is wrong in this?

#include
#include
using namespace std;
int main()
{
int x;
float z=0.5;
float y;
float total;
cin>>x;
cin>>y;
if(x>0&&x<=2000&&y>=0&&y<=2000){
if(x%5==0&&x<y)
total=y-x-z;
else if(x%5!=0&&x<y)
total=y;
else if(x%5==0&&x>y)
total=y;
else if(x%5==0&&x==y)
total=y;
cout<<setprecision(2)<<fixed<<total;}
return 0;
}
What is wrong in this?

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

#include <stdio.h>

int main(){
int amt;
float bal;

scanf("%d %f",&amt,&bal);

if( (amt % 5) != 0 || (amt > (int) bal))
{
	
}
else{
	bal = bal - (float)(amt + 0.5);
}
printf("%.2f",bal);
return 0;

}

can anyone tell why its wrong . when i use to run my program in my own dev cplus plus compiler its running . but ater submitting it shows wrong answer error
#include<stdio.h>
int main()
{
float y;
int x;
scanf("%d %f",&x,&y);
if(x<y&&(x%5==0))
printf("%.2f",y-x-0.5);
else
printf("%.2f",y);
return 0;
}

#include
using namespace std;
int main()
{
int n,ch;
cin>>n>>ch;
float sum=0;
if((n+0.5<=ch)&&(n%5==0))
{
sum=ch-(n+0.5);
cout<<sum<<"\n";
}
else
{
sum=ch;
cout<<sum<<"\n";
}
return 0;
}
What is wrong with mine code, codechef Judge is giving it wronf Answer??? PLease Help

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

import java.util.Scanner;
class Main{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int X;
double Y;

		X=input.nextInt();
if (X<=0||X>2000)
{		 input.close();
return;
}

		Y=input.nextDouble();
if (Y<0||Y>2000)
{
		 input.close();
return;
}
if(X%5==0)
	Y=Y-X-0.50;
System.out.println(Y);
 input.close();
return;

}
}

#include<stdio.h>
int main()
{
float bal;
int withdrawl;
scanf("%d",&withdrawl);
scanf("%f",&bal);
if(withdrawl>0&&withdrawl<=2000)
{
if(bal>=0&&bal<=2000)
{
if(withdrawl<bal)
{
if(withdrawl%5 == 0)
{
bal = bal-(withdrawl+0.50);
}
}
}
}
printf("%0.2f",bal);
return 0;
}

this code is working properly in online compiler of codechef .
but its not being accepted in the submit section.

#include<stdio.h>

int main()
{
   int X;
   float Y;
   scanf("%d %f",&X,&Y);
   if(Y<2000)
   if((X%5==0)&&(X<Y))
    Y=Y-X-.5;
   printf("%.2f",Y);
   
   return 0;
} 

it gets all test cases but shows ‘Wrong answer’

#include<stdio.h>
int main()
{
int x;
float y , z;
scanf("%d",&x);
scanf("%f",&y);
if(y>=0 && y<=2000);
{
if(x!=0 && x%5==0 && x<y)
printf("%f",y-x-0.50);
}
if(x%5!=0 || x>y )
printf("%f",y);
if(x==0 || x==y)
printf("%f",y);
return 0;
}
what is wrong with the code any one can run it on code blocks and can check it
i have to copy other’s code to proceed further

1 Like

#include
using namespace std;
int main()
{
int a;
float b;
cin>>a,b;
if(((a+0.50)<b) && (a%5==0))
{
cout<<(b-a-0.50);
}else {
cout<<b;
}

return 0;

}

//what is wrong in this? please tell.

import java.io.;
import java.util.
;
class joss_
{
public static void main(String args[]){
int c,i,t;
int s=0;
int e,h=0;
double f,g;
Scanner sc=new Scanner(System.in);
System.out.println(“”);
e=sc.nextInt();
f=sc.nextDouble();
g=f-e-0.5;
if((g<0)||((f%5)!=0)||(e>2000)||(f>2000))
{
g=f;
}
System.out.println(g);
}
}

What is wrong…?

Are you sure that your output is upto 2nd decimal place @anany_097?

because 120.000 is NOT 120.00 and hence would be flagged wrong.
Also, e is the money to be withdrawn. make sure that e is a multiple of 5.

Can anyone tell me that why the Codechef mark it as a wrong answer?

    #include <stdio.h>
 
    int main(void) {
	int x; //amount to withdraw
	float y; 	//initial balance
	
	scanf("%d %f",&x,&y);
	if((x>0) && (x<=2000) && (y>=0) && (y<=2000))
	{
		if((x<y) && (x%5 ) == 0)
			printf("%.2f",y-x-0.50);
		else
			printf("%.2f",y);
	}
	
	return 0;
}

withdraw**+0.50**>bankamount
This condition is necessary when in input is :
120 120.00
output should be :
120.00
not :
-0.50

3 Likes

#include <stdio.h>

int main(void)

{
int x=0;

float y=0;

scanf("%d",&x);

scanf("%f", &y);

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

{
    y = y - x - 0.50;

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

}

else

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

return 0;

}

how is this a wrong answer?