HS08TEST - Editorial

#include
#include
using namespace std;

int main()
{
int x;
float output,y;
std::cin >> x >> y;
if((x>2000 || x <=0) || (y > 2000 || y < 0))
{
return 0;
}
if(x>y)
{
std::cout << fixed <<std::setprecision(2) << y;
}
else
if(x % 5 != 0)
{
std::cout << fixed << std::setprecision(2) << y;
}
else
{
output = y - x - 0.50;
std::cout << fixed << std::setprecision(2) << output;
}
return 0;
}

WHAT IS WRONG IN THIS CODE???

#include<stdio.h>
main()
{
int x,y,p;float z;
printf(“enter the initial account balance”);scanf("%d",&y);printf(“enter the amount you want to withdraw”);scanf("%d",&x);
p=x%5;
if((0<=x<=2000)&&(0<=y<=2000)&&(x<y)&&(p==0))
{z=y-x-0.5;printf(“the current account balance is %.2f”,z);}
else
printf(""%.2f",(float)y);
}

#include<stdio.h>
main()
{
int x,y,p;float z;
printf(“enter the initial account balance”);scanf("%d",&y);printf(“enter the amount you want to withdraw”);scanf("%d",&x);
p=x%5;
if((0<=x<=2000)&&(0<=y<=2000)&&(x<y)&&(p==0))
{z=y-x-0.5;printf(“the current account balance is %.2f”,z);}
else
printf(""%.2f",(float)y);
}

include

using namespace std;

int main() {

// your code goes here

double bal;

int wid;

cin>>wid;

cin>>bal;

cout.precision(2);

cout.setf(ios::showpoint);

if(wid%5!=0||wid>bal-0.50)

    cout<<fixed<<bal;

else

    {

        cout<<fixed<<bal-wid-0.50;

    }

return 0;

}

1 Like

package main

import (
“strconv”
“fmt”
“math”
)
func main(){

fmt.Print("Enter Amount : ")

var amount string

fmt.Scanln(&amount)

var ar float64

i, _ := strconv.ParseFloat(amount,64)

h := math.Mod(i, 5.0)

if i <= 2000{

if h != 0 {

fmt.Print(ar)

}

if h == 0{

var va float64

va = ar - i - 0.50

fmt.Print(“Balance :”)

fmt.Print(va)
}
}

if i > 2000 {

fmt.Print(ar)

}

}

I wrote this code in go ,it works fine in my laptop ,but not in codechef. Is there any problem with it?

Don’t print any statements,printing only answer is enough

import java.util.Scanner;

class Atm{

public static void main(String[] args){

	Scanner s=new Scanner(System.in);
	System.out.println("enter amt to be withdrawn:");
	double a=s.nextDouble();
	System.out.println("enter the current amout in account");
	double b=s.nextDouble();
	if((0<a)&&(0<b)){
		if((a<=2000.0)&&(b<=2000.0)){
			if(a>b) System.out.println(b);
			if((a%5)!=0) System.out.println(b);
			if(((a%5)==0)&&(a==b)) System.out.println(b-a);
			if(((a%5)==0)&&(a<b)) System.out.println((b-a)-0.50);
		}
	}
}

}

whats wrong with this code?

2 Likes

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

what’s wrong with this??

import java.io.*;
class HS08TEST
{ public static void main(String args[])throws IOException
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
int x=Integer.parseInt(s.substring(0,s.indexOf(’ ‘)));
double y=Double.parseDouble(s.substring(s.indexOf(’ ‘)+1));
if( y-x-0.5<x+0.5 || x%5!=0)
{ System.out.println(s.substring(s.indexOf(’ ‘)+1));
}
else
{ double result=y-x-0.50;
String st=result+“”;
if(Integer.parseInt(st.substring(st.indexOf(’.')+1))>9)
{ System.out.println(st);
}
else
{ System.out.println((st+“0”));
}
}
}
}

what is wrong with this code? it is working perfectly in BlueJ but showing WA in CodeChef compiler

import java.util.Scanner;
import java.io.*;

class Codechef1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println(“Amount of cash you want to withdraw”);
int x = sc.nextInt();
if(0<x && x<=2000)
{
System.out.println(“Your intial account balance”);
double y = sc.nextDouble();
if(0<y && y<=2000)
{
if(x%5==0 && x<=y)
{
double rem = y-x-0.50;
System.out.println(“"+rem); } else { System.out.println("”+y);
}
}
}
}
}

WHAT’S Wrong with this code?

main()
{
int x;
double y=0.00,z=0.50;
cin>>x>>y;
while(x>0 && x<=2000 && y>=0 && y<=2000)
{
if(x%5==0 && x<y)
{
z= (y-x)-z;
cout<<setprecision(2)<<fixed<<z;
break;
}
else
cout<<setprecision(2)<<fixed<<y;
break;
}
return 0;
}

Why is this wrong?

#include<stdio.h>
int main()
{
int a,b,temp=0;
float c,d;
scanf("%d%f",&a,&c);
if(a%5==0 && a<=2000 && c<=2000.00)
{
b=1;
if(a<c)
{
temp=1;
}

}
else
{
	b=0;
}
if(b==1 && temp==1)
{
	printf("\n Successful Transaction");
	c=c-0.50;
	c=c-a;
	printf("\n Available Balance is %0.2f",c);
}
else if(b==0)
{
		printf("\n Invalid transaction or check your balance, Please enter amnount in multiple of 5");
			printf("\n Available Balance is %0.2f",c);
}
else
{
	printf("\n Insuficient fund");
	printf("\n Available Balance is %0.2f",c);

}

}

whats wrong in this program

#include
#include<stdio.h>
#include
using namespace std;
int main()
{
int x;
float y;
cin>>x;
cout<<"\t";
cin>>y;
if(x%5==0 && y-(x+0.5)>0)
{
cout<<"\n";
cout<<setprecision(2)<<y-(x+0.5)
}
else
{
cout<<"\n";
cout<<setprecison(2)<<y;

}
return 0;
}#include
#include<stdio.h>
#include
using namespace std;
int main()
{
int x;
float y;
cin>>x;
cout<<" “;
cin>>y;
if(x%5==0 && y-(x+0.5)>0)
{
cout<<”\n"<<setprecision(4)<<y-(x+0.5);
}
else
{
cout<<"\n"<<setprecision(4)<<y;
}
return 0;
}

Can someone tell me why my code worked with printf and not cout and setprecision??

X = int(input())
Y = float(input())

if X>0 and X<=2000 and Y>=0 and Y<=2000:
    if X<=Y and X%5==0:
        Y = float(Y - X - 0.50)
        print("%.2f" % Y)
    else:
        print("%.2f" % Y)

I say Runtime error but why?

@noswear

input contains only one line,but you are taking 2 lines of input and hence you are getting runtime error.Take single line of input and split them.Then your code will work fine.

Hey i m getting wrong answer. Can pls any1 pls me with this ?

code -

import java.util.*;
import java.util.Scanner;

class Dcoder
{
public static void main(String args[])
{

   double X, Y;
   Scanner scan = new Scanner(System.in);
 
   Y = scan.nextDouble();
   
   X = scan.nextDouble();
   
   X= X+(float)0.50;


   if( X<Y && X%5 == 0){
   	Y = Y-X;
   	System.out.println(Y);
      	}
   else{
   	System.out.println(Y);
   }	 
}

}

my code in java is not working please help me.

import java.util.*;

class sol{

public static void main(String []arg){

Scanner sc=new Scanner(System.in);

float w=sc.nextFloat();

float a=sc.nextFloat();

if(w%5!=0 || w>(a+0.5)){

System.out.printf("%.2f\n",a);

}
else{

System.out.printf("%.2f\n",a-w-0.5);
}
}

}

double b,a;
cin>>a>>b;
if((int)a%5 == 0 && a < b && a > 0)
cout<<fixed<<setprecision(2)<<b - a - 0.50<<endl;
else
cout<<fixed<<setprecision(2)<<b<<endl;

please tell me ,what’s the problem ???
i get 4 times WA

#include
#include
using namespace std;
int main() {
int x;
float y,a;
cin >>x >>y;
if(x%5==0&&y>x){
a = y-x-0.50;
cout<<setprecision(2)<<fixed<<a;
}
else if(x%5==0 && x>y) {
cout<<setprecision(2)<<fixed<<y;
}
else{
cout<<setprecision(2)<<fixed<<y;
}
return 0;
}

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

what is wrong in this code?It is working fine in my pc but shows run time error during submission