#include
#include<stdio.h>
using namespace std;
int main()
{
int amt;
float bal;
cin>>amt>>bal;
if(amt%5==0&&amt<bal)
{
bal=bal-amt-0.50;
}
printf("%0.2f",bal);
return 0;
}
#include
#include<stdio.h>
using namespace std;
int main()
{
int amt;
float bal;
cin>>amt>>bal;
if(amt%5==0&&amt<bal)
{
bal=bal-amt-0.50;
}
printf("%0.2f",bal);
return 0;
}
Instead of if(amt%5==0&&amt<bal)
, the condition should be if (amt % 5 == 0 && amt + 0.50 < bal)
.
import java.io.;
import java.lang.;
import java.math.*;
import java.text.DecimalFormat;
class codechef2{
public static void main(String ar[])throws IOException{
DataInputStream dis=new DataInputStream(System.in);
String s=dis.readLine();
String str[]=s.split(" ");
float n = Float.parseFloat(str[1]);
float x = Float.parseFloat(str[0]);
DecimalFormat f = new DecimalFormat(“##.00”);
if((x%5==0)&&(n-x>=0.5))
{
System.out.println(f.format((n-x)-0.50));
}
else
System.out.println(f.format(n));
}
}
The program will fail if the input is 50 50.25.In this case it should not allow to withdraw.So include the condition in the if loop(bal-amt>0.50).
#include<stdio.h>
void main()
{
int amt;
float n,b2,bal;
scanf("%d %f",&amt,&bal);
if((amt%5!=0) || (bal-amt<0.5))
{
printf("\n%0.2f\n",bal);
}
else
{
n = bal-amt-0.5;
printf("\n%0.2f\n",n);
}
}
Whats wrong in this code?The website shows runtime error.
@itsmepsk why you are printing \n two times. And you must use int main() with return 0 statement. I think that’s the culprit here.
@vineetpaliwal I got AC with if (amt % 5 == 0 && amt + 0.50 < bal)
. Probably because it didn’t check for bal == amt + 0.50
.
Thanks it worked.But what difference did it make?
In c++, you need an exit satement to know status of your program. And return 0 do that part.
@itsmepsk I don’t know about other programming languages but while submitting solutions in C and C++, all online judges require int main()
instead of void main()
. The former means that your main function returns an integer and hence at the end of the program you have to add the statement return 0;
.
‘return 0;’ means that the program ran successfully without any error.
i did a few programs without the return statement and they worked !
whats the difference between return 0 and return 1;