ATMProblem code: HS08TEST |
All submissions for this problem are available.
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.
Example - Successful Transaction
Input: 30 120.00 Output: 89.50
Example - Incorrect Withdrawal Amount (not multiple of 5)
Input: 42 120.00 Output: 120.00
Example - Insufficient Funds
Input: 300 120.00 Output: 120.00
| Author: | admin |
| Date Added: | 1-12-2008 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, FORT, HASK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, WSPC |
Comments
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
|
If you are still having problems, see a sample solution here. |

Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
WTF? Getting 'Wrong Answer' all the time, can't see why.
something very strange is happening here. I just converted a successful submission in C to Java and it gave "Wrong Answer"... what is going on?
You can view other successful java solutions to figure out your mistake.
how can we know for which test cases it is giving wrong answer?
omg what kind of dumb test set it is using?? :( i'm losing interest :(
@ramki A lot of users have got an ACC on this problem. You need to debug your code or rethink your algorithm if you are getting a wrong answer.
Phew,finally Done!!
?why m getting wrong ans?? even though logic and program is 100 % correct mr. admin plz put light on it...
The accepted submissions are accessible. You may want to run them on random test data and check if your outputs match.
is my code wrong if it gives 30 90 as o/p for the i/p 30.00 120.00
plz will ny one see my solution..m a newbie..need help..
my code works f9 with dev c 4.9.9.2 whereas the site says compile error someone plz help
atleast tell which compiler is being used...nyone out there
I'm confused too as to why im getting a "wrong answer" response as my code appears to produce the exact same output for each of the examples given. Any help would be very welcome thanks
@Nilesh @Bob All solutions for this problem are available. Why don't you take any of the accepted submissions and try running them against some random test cases and check if the output matches.
@Nilesh Please don't spam the comments' section.
@Nilesh For what compilers we use and other questions, please read http://blog.codechef.com/2009/06/29/frequently-asked-questions/ and http://www.codechef.com/help
hey...what compile error man???
i've successfully compiled this program...
but still its showing me compile error...
http://www.codechef.com/help/ Search for a sample solution in java on this page. Also, if you have other questions, you can check out http://blog.codechef.com/2009/06/29/frequently-asked-questions/ You are getting a compile error because the name of your class is not Main.
I am getting run time error saying (NZEC) . I help, its wriiten non zero exit code. My code is in java. Its running successfully in my system. class name is Main. Please help.
There could be a problem with the I/O. You might want to check that out.
yeah got it thanks .. problem was with io only.
You are welcome :)
Hi. Why is the time limit on this problem 1 second and I've seen accepted entries with a time of more than 2 seconds?
Is there different time limits for different languages?
I'm asking because I'm usung python and execution time is an issue.
Thanks a lot :)
I have submitted two answers
10 10.25
wat the hell is gng
You can check the status of
i get run time error every
Check out the FAQ for more
Check out the FAQ for more information on run time errors.
#include main() {
@Rahul, please remove your
@Codechef Drupal Admin - I
I am getting run time error
I am getting run time error saying (NZEC) . I used help, its wriiten non zero exit code. My code is in java. Its running successfully in my system. class name is Main. I have throws java.io.IOException also. Please help.
You probably have some issues
You probably have some issues with the Input / Output.
Humen print kya karana
Humen print kya karana hai:
Input:
30 120.00
Output:
89.50
yaa phir yeh karana hai:
30 120.00
89.50
Hello Admin plz reply soon
all the admins are frustating nobody helps
thinks they great coderss,all useless
class Main{ public static
class Main{
public static void main (String[] args) throws java.lang.Exception{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
int x,flag=1;Double y;
x=Integer.parseInt(r.readLine());y=Double.parseDouble(r.readLine());
if(x%5==0 && (y-x)>=.5)y=y-x-.50;
System.out.println(y);
}}
Same code submitted by other user gets accepted
par mere mein RunTime Error(NZEC)
Admin where r u
Your code gives a runtime
Your code gives a runtime error on the sample input because the input is on one line. You don't need the admin when you can test your program by yourself.
@sumit You just have to print
@sumit You just have to print 89.50 as the output.
i dont understand the meaning
i dont understand the meaning of NZEC compiler error. Can you please guide me?
It is not a compile time
It is not a compile time error. You can get a NZEC if your program returns with an status other than 0. You can check the FAQ at http://blog.codechef.com/2009/06/29/frequently-asked-questions/ for more information.
what problems do fall under
what problems do fall under the category of OTHER in runtime error?
What exactly do you mean ?
What exactly do you mean ?
#include<stdio.h> void
#include<stdio.h>
void main(){
unsigned int w;
float total,b;
char ch='Y';
while(1)
{
printf("enter the amount u would withdraw(c that it is multiple of 5)n");
scanf("%d",&w);
printf("enter the balance");
scanf("%d",&b);
if(b>0 && b<2000)
{
if(b>w && w%5==0)
total=b-w-0.50;
else
printf("enter withdraw amt as multiple of 5 and <=balcancen");
}
else
printf("enter the balnce <2000 n >0n");
printf("do u want to continue transcation Y/Nn");
scanf("%c",&ch);
if(ch=='N'|ch=='n')
{printf("thank you ");
break;
}
}
#include<stdio.h> void
#include<stdio.h>
void main(){
unsigned int w;
float total,b;
char ch='Y';
while(1)
{
printf("enter the amount u would withdraw(c that it is multiple of 5)n");
scanf("%d",&w);
printf("enter the balance");
scanf("%f",&b);
if(b>0 && b<2000)
{
if(b>w && w%5==0){
total=b-w-0.50;
printf("current balnce:%f",total);
}
else
printf("enter withdraw amt as multiple of 5 and <=balcancen");
}
else
printf("enter the balnce <2000 n >0n");
printf("do u want to continue transcation Y/Nn");
scanf("%c",&ch);
if(ch=='N'|ch=='n')
{printf("thank you ");
break;
}
}
#include<stdio.h> void
#include<stdio.h>
void main(){
unsigned int w;
float total,b;
char ch='Y';
while(1)
{
printf("enter the amount u would withdraw(c that it is multiple of 5)n");
scanf("%d",&w);
printf("enter the balance");
scanf("%d",&b);
if(b>0 && b<2000 && b>w-0.50){
if((int)w%5==0)
b=b-w-0.50;
else
printf("enter withdraw amt as multiple of 5 and <=balcancen");
}
else
printf("enter the balnce <2000 n >0n");
printf("current bal after transcation:%f",b);
printf("do u want to continue transcation Y/Nn");
scanf("%c",&ch);
if(ch=='N'|ch=='n')
{printf("thank you ");
break;
}
}
}
Do not post code here.
Do not post code here.
What is wrong in this code?
#include<stdio.h>
int main()
{
int withdraw= 0;
float total = 0;
while(true)
{
scanf("%d %f",&withdraw,&total);
if(withdraw>total || withdraw%5 )
{
printf("%.2f n", total);
}
else
{
printf("%.2f n", total - withdraw - 0.5);
}
}
return 0;
}
It is not correct code. Your
It is not correct code. Your program never terminates.
Hi all, I have tried to run
Hi all,
I have tried to run the following code. But it is giving error on submiting the code.
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException,
NumberFormatException {
BufferedReader r = new BufferedReader(new java.io.InputStreamReader(
System.in));
String[] s = r.readLine().split(" ");
double x=Double.parseDouble(s[0]);
double y=Double.parseDouble(s[1]);
if ((x>= y)|| (x%5 != 0)) {
System.out.println(y);
} else {
System.out.println(y- x - 0.50);
}
}
}
Please help me in finding the point of error.
Thanks in advance,
#include <stdio.h> #include
#include <stdio.h>
#include <conio.h>
void main()
{
int with;
float cur;
clrscr();
scanf("%d %f",with,cur);
if(!((with>=cur)||((with%5)!=0)))
cur=cur-with-0.5;
else;
printf("%f",cur);
getch();
}
what is wrong with this code...it shows compiler error..
can any one say how it happens???
@harikrishnan: firstly you
cn any body tell me wt's prob
cn any body tell me wt's prob in this code
#include<stdio.h>
int main ()
{
float x,y;
scanf("%f %f",&x,&y);
if(x<y)
{
if(int(x)%5==0)
{printf("%.2f",((y-x)-.5));
}
else
{printf("%.2f",y);
}
}
else
printf("%.2f",y);
return 0;
}
My Java program runs with all
My Java program runs with all given test cases and gives correct answers, but after submission, it says wrong answer!!??
the program is taking input from standard IO and is considering both the values to be written one after the other and seperated with a bank space.
the file is named as Main.java, still i get problems!!
Try these test
Try these test cases
INPUT
4.5 5
5 5.5
5 5
3.99 4.5
5.0 5.49
5.0 5.51
OUTPUT
5.00
0.00
5.00
4.50
5.49
0.01
#include<stdio.h> #include<c
#include<stdio.h>
#include<conio.h>
void main(){
int w,B;
float R;
clrscr();
printf("enter the money for withdrawal");
scanf("%d",&w);
printf("enter the current balance");
scanf("%d",&B);
R=(float)B-w-0.5;
if(w%5==0&&w<B){
printf("%.1f",R); }
else{
printf("%d",B);}
getch();
}
what's wrong in this solution it is showing compilation error
Read the FAQ.
Read the FAQ.
@VARUN SHARMA Thanks Varun
@VARUN SHARMA
Thanks Varun bhai!!
i got where my code makes the flaw!!
Ok... with php, you cannot do
Ok... with php, you cannot do a number_format with this...
For some reason in php - output that has been formatted to have a precision of 2 is invalid...
#include<iostream>using
#include<iostream>
using namespace std;
void main(){
int a;
float b,c;
cin>>a;
cin>>b;
if(a%5==0)
if(a<b)
c=(b-a)-0.5;
else
c=b;
else
c=b;
cout<<c;
int i;
cin>>i;
}
#include<iostream>using
#include<iostream>
using namespace std;
int main()
{
int amt;
double inamt;
cout<<"Enter the transaction amount"<<endl;
cin>>amt;
cout<<endl<<"Enter the initial balance";
cin>>inamt;
if(amt%5==0&&amt<=inamt)
{
float balance=inamt-amt-0.5;
cout<<endl<<balance;
}
else
cout<<inamt;
if(amt>=inamt||amt%5!=0)
cout<<inamt;
return 0;
}
impossible to do in C
impossible to do in C
Thanks Varun .. I hope
Thanks Varun .. I hope Codechef also tells us inputs where our program failed .. That will be highly appreciated.
hey Varun X can only be
hey Varun X can only be integer ... how r u taking both as float
its checking is wrong .. its
its checking is wrong ..
its does not contain that 2000 boundation.
when i am making the program with this condition its reply with "wrong answer" but without this confition its accepted my answer.
i have tc2 compiler.how can i
i have tc2 compiler.how can i install gnu compiler .i downloaded it but unable to do the next step.please help me out
Can anyone pls tell me wt's
Just try a variety of test
Just try a variety of test cases. One class of test case will show you what you've done wrong, and it shouldn't take you long coming up with it if you're methodical with your test cases.
package atm;import
package atm;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main
{
public static final double ATM_FEE = .5F; // 50-cent ATM fee
public static final int MULT = 5; // Withdrawal multiple
public static void main(String[] args)
{
Scanner getInput = new Scanner(System.in);
DecimalFormat dollars = new DecimalFormat("#0.00");
double WithdrawalAmt = getInput.nextDouble();
double Balance = getInput.nextDouble();
double NewBalance = 0;
boolean LowBalance = (WithdrawalAmt >= Balance);
boolean NotMultiple = (WithdrawalAmt % MULT != 0);
boolean LessZero = WithdrawalAmt <= 0;
if(LowBalance || NotMultiple || LessZero)
{
System.out.println(dollars.format(Balance));
}
else
{
System.out.println(dollars.format(Balance - (WithdrawalAmt +
ATM_FEE)));
}
}
}
Keep getting "Wrong Answer" even though all of my test cases have passed muster.. I'm not quite sure what I'mt missing
By the way, when I submitted
By the way, when I submitted the code (see above) I did erase "package atm;"
Your mistake is specifically
Your mistake is specifically pointed out in the second sentence of the problem statement.
Steve, "The cash machine will
Steve,
"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)."
In my code, "NotMult" is there to determine if the remainder of (WithdrawalAmt / 5) is anything other than 0. If it is, then the amount that the user is requesting to withdraw is not a multiple of 5. This satisfied the first part of the second sentence.
The second part says "...enough cash to perform the withdrawal transaction (including bank charges)." I have set LowBalance equal to (WithdrawalAmt >= Balance):
Case 1: The user attempts to withdraw $120 when only $110 is available (greater than). "LowBalance" would catch this and cause the original balance to print out, as specified in the problem statement.
Case 2: The user attempts to withdraw $40 when his account balance is $40 (or equal to). Since $40.50 >= $40, "LowBalance" would catch this and cause the original balance to print out, as specified in the problem statement.
I have read, and reread both the second sentence of the problem statement, and my own code. I've also done more tests, and I don't see what it is that I'm missing.
Thanks for taking the time to glance over my code.
The only thing that I can
The only thing that I can think of, Steve, is that perhaps LessZero should be < instead of <=. Because of this user is simply checking account balance, the withdrawal amount would be 0, but he or she would still be subject to the $0.50 ATM fee
Scratch that.. 0 < X <= 2000.
Scratch that.. 0 < X <= 2000. Wish I could delete posts :)
is there anyway we can delete
is there anyway we can delete the solutions that we have submitted? i submitted the same solution thrice by mistake...
@Stephen Thank you so much!
@Stephen
Thank you so much! :)
@Stephen Thank you so much!
@Stephen
Thank you so much! :)
wouldn't compile without a
wouldn't compile without a return 0 in main... lame
My code is executing
My code is executing perfectly on my system but i m getting runtime error from the judge. What is the error??
Are you returning 0 at the
Are you returning 0 at the end of your program?
yes u can check my code.
yes u can check my code.
Then there might be some
Then there might be some problem with the way you are performing I/O
Working fine:: taking input
Working fine:: taking input withdrawal amount as integer, balance as float and checking conditions and displaying balance. Also some working solns given on the site take withdrawal amount as float though it is specified in question that it is an integer.....?????
You have exit(1) in your
You have exit(1) in your code.. that specifically says to exit with an error.
Remember in Java to send
Remember in Java to send output as number not text.
#include<stdio.h>int
#include<stdio.h>
int main(void)
{
int i;
float j;
scanf("%d %f",&i,&j);
if(i==0 || i>2000 || j>2000 || i>j || i%5!=0) printf("%.2f",j);
else printf("%.2f",j-i-0.5);
return 0;
}
i'm new here.......
can't understand what is wrong with this code......
please inform me....
and also
please tell me how to perticipate in the compete
You are missing something in
You are missing something in the second sentence of the problem statement.
what the heck is going on
what the heck is going on dude? It keeps testing wrong...this program is written perfectly. All test cases I could think of... WHAT THE!!
It is wrong. For the same
It is wrong. For the same reason as mentioned above; the case you are missing is specifically mentioned in the problem statement.
ahhh this is ridiculous
ahhh this is ridiculous ;o
I don't see what's wrong with my code anymore...I'm doing to bed now. LoL
@stephen thank u . got
@stephen
thank u .
got accepted
please tell me how to
please tell me how to perticipate in the january algo challenge....
is it possible without forming a team?
if not , how can one form a team????
please admin or aniruddha or stephen.....
answer me..
hello sir i have succesfuuly
hello sir i have succesfuuly run this program in turbo c.but here it is shown wrong answer.
here is my program:
#include<stdio.h>
int main()
{
float y,z;
int x;
printf("input:");
scanf("%d %f",&x,&y);
if(((float)x)>y)
{
printf("%.2f",y);
}
else if(x%5==0)
{
z=(y-x)-0.50;
printf("%.2f",z);
}
else
{
printf("%.2f",y);
}
return 0;
}
so cn u give me ans why it is worng.
my email_id is:rajesh91bhatia@gmail.com
do not use dat "
do not use dat " printf("input:"); "
if u will read d faq its wriiten over der u only need to take d i/p n giv its o/p nothin xtra.
n u better check dis i/p "120 120.00"
Can someone point error in
Can someone point error in below program
import java.text.NumberFormat;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String input [] =r.readLine().split("\s+");
double withdrawAmount = Double.parseDouble(input[0]);
Double totalAmount = Double.parseDouble(input[1]);
if(withdrawAmount%5==0&&(withdrawAmount+0.5)<=totalAmount)
{
double balance = totalAmount-(withdrawAmount+0.5);
System.out.println(roundTwoDecimals(balance));
}
else
{
System.out.println(roundTwoDecimals(totalAmount));
}
}
static String roundTwoDecimals(double d)
{
NumberFormat fmt =NumberFormat.getInstance();
fmt.setMaximumFractionDigits(2);
fmt.setMinimumFractionDigits(2);
return fmt.format(d);
}
}
#include<stdio.h> void
#include<stdio.h>
void main()
{
int x;
float b;
printf("Enter withdrawal amt and bal");
scanf("%d %f",&x,&b);
if(x%5==0 && x<=2000 && x>0 && x<b && b<=2000 && b>0)
{
printf("%.2f",(b-x)-0.5);
}
else
{
if(b>2000)
{
printf("balance cannot be greater than 2000");
getch();
exit(0);
}
printf("%.2f",b);
}
getch();
}
@sandipa read FAQ
@sandipa read FAQ
your code has many errors
your code has many errors like you cannot use getch(). . .main must return an integral value. . . .
moreover you need not to print text like enter money etc etc. . .as your program is judged by a computer judge . . .So please go through http://www.codechef.com/freelinking/FAQ once ! ! !
/usr/local/bin/java compile:
/usr/local/bin/java compile: line 3: 28306 Aborted /usr/local/jdk/bin/javac -d /tmp /sources/Main.java 1>&-
what does this error mean?
//ATM import
//ATM
import java.lang.*;
import java.io.*;
class operations
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
double y;
double x;
double z;
double charge;
public void input()throws IOException,NumberFormatException
{
//AMOUNT TO BE WITHDRAWN
System.out.println("Enter amount of money to be withdrawn");
try
{
x=Double.parseDouble(br.readLine());
}
catch (Exception e)
{
System.out.println("Enter double value");
}
if((x%5!=0))
{
System.out.println("Enter multiple of 5");
}
else if((x<=0)||(x>2000))
{
System.out.println("Enter proper value");
System.exit(0);
}
//code for entering balance
System.out.println("Enter your balance");
try
{
y=Double.parseDouble(br.readLine());
}
catch (Exception e)
{
System.out.println("Enter double value");
}
if((y<=0))
{
System.out.println("Enter positive balance");
System.exit(0);
}
else if ((y>=2000))
{
System.out.println("Balance should not exceed 2000");
System.exit(0);
}
}
public double withdraw()
{
z=y-x;
charge=z-0.50;
if((x>=y)||(x%5!=0)||(charge<0))
{
System.out.printf("%.2f%n",y);
}
else
{
System.out.printf("%.2f%n",charge);
}
return z;
}
}
class ATM
{
public static void main(String[] args) throws IOException,Exception
{
System.out.println("Hello,Welcome to Priya's Account!");
operations o=new operations();
o.input();
o.withdraw();
}
}
i dont know why it is giving compilation error...it is checking all test cases
Read the FAQ. You must have a
Read the FAQ. You must have a public class called Main.
I submitted the solution in c
I submitted the solution in c and used .2f and .02f for precision, how come both of the solutions got accepted?
// ATM transactions#include
// ATM transactions
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int withdraw_amount;
double balance;
cin >> withdraw_amount >> balance;
cout << setprecision(2) << fixed;
if(withdraw_amount % 5 != 0 || withdraw_amount > balance)
{
cout << balance << endl;
}
else
{
balance = balance - withdraw_amount - 0.5;
cout << balance << endl;
return 0;
}
}
What's wrong with this one can anyone please explain to me? I'm getting a runtime error.
Very new to this site.. Can
Very new to this site..
Can someone please let me know if my submission format is correct?
-----------------------------------------------------------------------
#!/usr/bin/perl
$withdraw=$ARGV[0];
$balance=$ARGV[1];
if($withdraw < $balance){
$check_case = ($withdraw%5);
if(!$check_case){
$remain_balance = $balance - ($withdraw + 0.5);
print $remain_balance;
}
else{
print $balance;
}
}
else{
print $balance;
}
How about this..! It works
How about this..!
It works perfect for me when I run from command line...!
-----------------------------------------------------------
#!/usr/bin/php
<?
$user_withdrawl = $argv[1];
$account_balance = $argv[2];
$new_balance = 0;
if($user_withdrawl < $account_balance){
if(!($user_withdrawl%5)){
$new_balance = $account_balance - $user_withdrawl - 0.5;
}
else{
$new_balance = $account_balance;
}
}
else{
$new_balance = $account_balance;
}
echo sprintf("%.2f", $new_balance);
?>
Can anyone of you please look
Can anyone of you please look into my php code and let me know what format I need to publish the code in.
http://www.codechef.com/viewsolution/171195
Please get back to me so I can actively participate on furthermore competition.
#include<iostream>#include<io
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
unsigned int X;
float Y;
cin>>X>>Y;
if(X>=Y || X%5!=0)
cout<<fixed<<setprecision(2)<<Y;
else
cout<<fixed<<setprecision(2)<<float (Y-(X+0.50));
system("pause");
return 0;
}
This code is rejected. Can anyone tell what's the problem with it?
@yuvrav and Kunal - both of
@yuvrav and Kunal - both of you read the FAQ.
I dont know how i m getting
I dont know how i m getting wrong answer. some one help or else authorities must look in to it
#include<stdio.h>
int main()
{
float bal;int wid;
scanf("%d",&wid);
scanf("%f",&bal);
if(wid>bal)
;
else if(wid%5==0)
bal=bal-wid-0.5;
printf("%0.2f",bal);
return 0;
}
Read the FAQ. And also the
Read the FAQ. And also the problem statement, as you are ignoring part of it.
What the fuck? hey dude! its
What the fuck?
hey dude! its working correctly on my environment.....
hey will you plz tell me how
hey will you plz tell me how itz getting tht eror
#include<stdio.h>int main(){
#include<stdio.h>
int main()
{
int amt;
float bal;
scanf("%d %f",&amt,&bal);
if((amt>0) && (amt<=2000) && (amt%5==0) && (amt<(bal+0.50)) && (bal>0) && (bal<=2000))
{
bal=bal-amt-0.50;
}
printf("%.2f",bal);
return 0;
}
this code is working correctly for all example cases in my machine on dev c++ as well on gcc compiler on ubuntu
can sm1 plz tell me wat changes to do to make this solution as accepted""
FAQ
FAQ
i have written the code using
i have written the code using java. its working fine on my computer. but its giving a runtime error on submission.
If you're getting a runtime
If you're getting a runtime error then you have made a mistake, so it won't be working fine on your computer.
i am getting wrong answer but
i am getting wrong answer but i dont know y??
can any one help me plz.
#include<stdio.h>
int main()
{
int x1;
float x;
scanf("%d %f",&x1,&x);
if(x1 > x)
{ printf("%.2f",x);}
else if(x1 % 5 ==0) {
if(x1 < x)
printf("%.2f",((x-x1)-0.50));
else
printf("%.2f",x); }
else
{ printf("%.2f",x);}
return 0;
}
What you are doing wrong is
What you are doing wrong is clearly specified in the problem statement - read it again. And please don't post code - see the FAQ.
Getting a Runtime Error NZEC
Getting a Runtime Error NZEC everytime...ive re run the Code several times with the given Input...and everytime i get the correct output ...but when i submit it i get a rumtime error
As you've already realised,
As you've already realised, it was obvious why it was giving a runtime error. You weren't testing your code properly; the input appears on one line and your program couldn't cope with that.
It's now getting a wrong answer because you haven't handled the various cases properly. There aren't many to test so it should be easy to find the one it fails on.
The Code is working perfectly
The Code is working perfectly on ALL the 3 Conditions...dont know why is it giving me Wrong Answer....i have tested the code with all the Possible Conditions
No you haven't, The problem
No you haven't, The problem statement even specifically mentions something that you are doing wrongly. If you can't find the bug then you haven't read the problem statement.
#include<stdio.h>main(){float
#include<stdio.h>
main()
{
float b,c=0.00;
int a;
scanf("%d %f",&a,&b);
if((a%5)!=0||b-a<.50)
{
printf("n%.2f",b);
}
else
{
c=b-a-.50;
printf("n%.2f",c);
}
return 0;
}
HEEEELP MAN!WORKS FYN ON MA MACHINE!WRONG ANSWER?DARN!
When I go through all the
When I go through all the comments I realize not many people have patience :)... Feynman was sooo right :) [duh!]
while submitting if i choose
while submitting if i choose ... c++ as language.. then a message pops.. that i can't submit in this language... try the link!! wht's this... i can see.. other people. submitting in c++ !!
@Stephen, do you think that a
@Stephen, do you think that a Bank will let you do any transaction you want without knowing that you have enough money to pay up for it? -_- hehe
@Nitin Kumar, I got this
@Nitin Kumar, I got this problem too when I choose C++ (g++ 4.3.2). I managed to submit it by choosing C++ (g++ 4.0.0-8). Hope this helps!
@pangsit .. thanx!! i too
@pangsit .. thanx!! i too submitted it in g++ 4.0.0-8 and it worked for me..
It is working fine, but not
It is working fine, but not sure it is always throwing runTime error everytime
this is python code
wmoney = int(raw_input())
tmoney = float(raw_input())
if (wmoney%5)==0 and ((tmoney - 0.50) >= wmoney):
bal = tmoney - wmoney - 0.50
else:
bal = tmoney
print '%.2f'%bal
is it need input by separated space ...
any clue
The sample input is pretty
The sample input is pretty clear.
using System;using
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("enter the amount for withdrawl?");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter the balance? ");
b = Convert.ToInt32(Console.ReadLine());
if( (a>0 && a<2000) && (b>0 && b<2000) )
{
if (a % 5 == 0 && a<b )
{
Console.WriteLine(String.Format("{0:0.00}", b - a - 0.5));
Console.WriteLine("successfull withdawl");
}
else if (a > b)
{
Console.WriteLine("Insufficient balance");
Console.WriteLine("balancee is" + b);
}
else
{
Console.WriteLine("not a multiple of 5");
Console.WriteLine(b);
}
}
else
Console.WriteLine("amount is greater than 2000! limit exceed!");
Console.ReadLine();
}
}
}
c# code
Giving Right result... check it further....
Read the FAQ.
Read the FAQ.
#include <iostream>#include
#include <iostream>
#include <conio>
void main()
{
int x,y;
cin>>x>>y;
if(x%5==0)
{
if(y<=(x+0.5))
cout<<x;
else
cout<<y-(x+0.5);
}
getch();
return 0;
}
whats wrong in this code ,it is showing compile time error.............
FAQ
FAQ
iin any wrong case (like if
iin any wrong case (like if one inputs outside the limits )we have to print the balance
suppose the balance is outside limits then also we have to print balance only.
If the problem says a number
If the problem says a number will lie between two bounds then it will.
frns i can't upload any
frns i can't upload any solutin here ..!! it says wrong password or login ..... why i am getting this error ?? plz help me to upload a solution ....frns plz plz plz :)
hi i tried to run ATM code
hi i tried to run ATM code using codechef compiler it shaws me a compiler error while the same programm runs successfully on my TURBO C compiler .i dont know why is this happens
pls read the code below and tell me if there is any erro or any of the conditions that is given in the question is not satisfied
#include<stdio.h>
#include<conio.h>
void main()
{
int ibalance,iamount;
float ioutput;
clrscr();
printf("enter the amount to be withdrawn and initial balancen");
scanf("%d %d" ,&iamount,&ibalance);
if(iamount<ibalance && iamount%5==0 )
{
ioutput=ibalance-iamount-0.50;
printf("your current balance is %f n",ioutput);
}
else if(iamount>ibalance)
{
printf("enter amount below the balance");
}
else if(!(iamount%5==0))
{
printf("enter the amount multiple of 5");
}
getch();
}
FAQ
FAQ
(code removed)
(code removed)
Please do not post code. Read
Please do not post code. Read the FAQ.
if pooja enters a withdrawl
if pooja enters a withdrawl amount of '$0',do we need to deduct $0.50 from her account balance.
#include<stdio.h> int
#include<stdio.h>
int main()
{
float bal=0.0,check;
int withdraw;
scanf("%f %d",&bal,&withdraw);
if((withdraw+0.50)<=bal && withdraw%5==0 &&bal<=2000)
bal-=(withdraw+.50);
printf("%.2f",bal);
return 0;
}
This is my code and it works very well in turbo C.. but it is mentioned as wrong answer.. Wy it is so??
Can anyone help me????
You're mixing up which
You're mixing up which numbers in the input are integers and which aren't.
I tried pasting the code, but
I tried pasting the code, but I got this message : "You can't submit in this language for this problem. Try link." I got the same thing while uploading the code.
HI ,CAN ANYBODY PLEASE TELL
HI ,CAN ANYBODY PLEASE TELL ME WHAT IS WRONG WITH MY CODE
http://www.codechef.com/viewsolution/297947
PLEASE HELP!!
@Ayush-You are not printing
@Ayush-You are not printing the result only....
@Anish- Thanks
@Anish- Thanks
i cannot post my code. it
i cannot post my code. it says wrong login or password... :(
Hi, I am getting Runtime
Hi,
I am getting Runtime error when i submit my solution for the problem. Pls share me why it comes and what might be the reason behind it.
Note: pls dont point to FAQ
Thanks,
BalajiKandan
Thanks, i have fixed it....
Thanks, i have fixed it.... :)
time limit exceeded wtf!!!
time limit exceeded wtf!!!
#include<stdio.h> main() { f
#include<stdio.h>
main()
{
float b;
int w;
scanf("%f%d",&b,&w);
if(w%5==0)
{
if(w<b-.5)
printf("%.2f",b-w-.5);
else
printf("%.2f",b);
}
else
printf("%.2f",b);
}
can i please please know wats wrong with this code....this is happenin lik innumerable times!!!!!!!!
#include<stdio.h>main(){float
#include<stdio.h>
main()
{
float t_a;
int w_d;
printf("Enter the amonut and available balnace");
scanf("%d%f",&w_d,&t_a);
if (w_d % 5==0 && w_d< = t_a - 0.5 )
{ printf("outputn");
printf("%f",t_a-w_d-0.5);
}
else if
(w_d % 5 !=0 || w_d < t_a-0.5 )
printf("%f",t_a);
}
#include <iostream> using
not bad for starting.
not bad for starting.
i am unable to submit
i am unable to submit solutions at this moment??what is the problem?
#include<stdio.h>void
#include<stdio.h>
void main()
{
float balance;
int amount;
scanf("%d%f",&amount,&balance);
if((amount%5)==0&&(amount<balance))
printf("%.2f",balance-amount-0.50);
else
printf("%.2f",balance);
}
#include<stdio.h> int
#include<stdio.h>
int main()
{
float prev_balance;
int withdrawal;
scanf("%d%f",&withdrawal,&prev_balance);
if((withdrawal<prev_balance) && ((withdrawal%5)==0))
prev_balance=prev_balance-withdrawal-0.50;
printf("%.2f",prev_balance);
getch();
return 0;
}
plaese tell me why codechef
plaese tell me why codechef is giving response as wrong answer
It is possible for your
It is possible for your program to output a negative balance.
My first successful
My first successful submission. Good one to start with.
What is wrong with this
what is wrong with this it is
#include<iostream>#include<m
#include<iostream>#include<math.h>using namespace std;main(){ int c; float d=0,u=0,Y,X,x; cin>>X>>Y;x=floor(X)+.50;c=X;if (X-floor(X)==0 && c%5==0 && Y>=x) {Y=Y*100;x=x*100; Y=Y-x; Y=Y/100;} u=Y-floor(Y); Y=floor(Y);cout<<Y<<".";d=floor(u*10);cout<<d;d=u*100-d*10;cout<<floor(d);
return 0;}
To: any one who knows....this was the program I wrote n cant understand that y the out put is 5.48 when i give input> 5 5.49 :(here Y=5.49 and since it is < 5 + 0.5 the output should b 5.49if any one can help plzzzzzz tell
mischief managed :Dplz ignore
Few points to be kept in
Few points to be kept in mind:
1. only the withdrawal amount has to be a multiple of 5
2. the withdrawal amount to be an INT
3. Don't display unnecessary "cout"s. The solution will not get accepted even if it running perfectly on your compiler.
4. The output will be the balance entered itself, unless the amount is an integer multiple of 5 and is <bal-.5
Happy Coding
i m getting error ... " you
i m getting error ... " you cant submit in this language for this problem " ..while i m submitting it in c language !! wat is the problem.. !! somebody help !! i have submitted the following
#include<iostream>
using namespace std;
int main()
{
double x;
int y;
char ch='y';
cout<<"cash at ur accountn";
cin>>x;
while (ch=='y')
{
cout<<"amount u want to withdrawn";
cin>>y;
if (y>x)
cout<<"insufficent fundsn";
else
{ if(y%5==0)
x=((x-y)-0.5);
cout<<"new account balance = n"<<x;
cout<<"do u want to withdraw more y/n";
cin>>ch;
}
}
return 0;
}
Not able to submit my
Not able to submit my solution. Prompt says :
"You cannot submit in this language for this problem. Try link."
What does it mean? My solution uses C++ 4.3.2 .
any body .plz tell why this
any body .plz tell why this is a wrong answer.....
#include <iostream>
using namespace std;
int main()
{
float a,bal;
cin>>a>>bal;
if(((int)a % 5)==0&& (a+0.50)<=bal)
{
bal= bal-(a+0.50);
cout.precision(4);
cout<<bal;
}
else
{
cout.precision(4);
cout<<bal;
}
return 0;
}
plzzzzzzzzzzzz.................
Dead Thread!
Dead Thread!
im uplaoding my code
im uplaoding my code programmed in dev C++ 4.9.9.2 supporting GCC
here is my code...its running perfectly in software
when im uplaoding here, its saying cant uplaod in the selected language..my language is C++ ( gcc 4.3.2)
#include<iostream>
using namespace std;
int main()
{
int draw;
float bal;
cin>>draw;
cin>>bal;
if (draw % 5==0)
{
if (draw < bal-0.50)
bal=bal-float(draw)-0.50;
cout.precision(2);
cout<<bal;
}
else{ cout.precision(2);
cout<<bal;}
return 1;
}
I'm submiting this code in
I'm submiting this code in C:
#include <stdio.h>
int main() {
float balance=0.0, money=0.0;
scanf("%f", &money);
scanf("%f", &balance);
(money >= balance || ((int)money%5 != 0)) ? printf("%.2fn", balance) : printf("%.2fn", balance-money-0.50);
return 0;
}
This works perfectly fine in my machine. But here I'm getting messages like: "wrong answer and sorry internal error"
Can anyone help me in this? I hope, I'm printing what question has asked :P
Ignore the internal errors;
Ignore the internal errors; they have been happening regularly recently and you can still see the result of your submission via the My Submissions page.
The wrong answer is because you are not printing what the question has asked. Read the second sentence of the problem statement; you aren't doing what it says.
I m a C# user, how can i read
I m a C# user, how can i read two integers from a single line, how z that possible?
plz put on some light
@ravi Here is my C# Accepted
@ravi
Here is my C# Accepted Code, FYI:
using System;
using System.Collections.Generic;
using System.Text;
namespace CodeChef
{
class Program
{
static void Main(string[] args)
{
for (string input = Console.ReadLine(); !string.IsNullOrEmpty(input); input = Console.ReadLine())
{
string[] parameters = input.Split(' ');
// Parse parameters
int withdraw = int.Parse(parameters[0]);
double balance = double.Parse(parameters[1]);
// Output
if (withdraw % 5 == 0 && balance - withdraw >= 0.5)
{
Console.WriteLine("{0:F2}", balance - withdraw - 0.5);
}
else
{
Console.WriteLine("{0:F2}", balance);
}
}
}
}
}
For some reason(s), the
For some reason(s), the website shows compiling error for .java files; while the same files compile, run and give correct outputs for all the test cases that I have tested..
I guess, the better idea is to practice the problems provided on the website and check the results yourself instead of wasting time on submitting and reformatting the running code. But then it is not always possible to think of all the possible test cases to check your code's precision.
Another interesting observation is that most of the successful submissions here are in C/C++.. I have rarely seen any "successful" submission of .java file.. Probably the website needs to provide more specific guidelines on how to format/submit the .java files specifically for codeChef compiler.
However, nice source to practice and learn..
Thank you Directi...
Did you notice right below
Did you notice right below the 'Post new comment' heading was 'Have you browsed through the FAQ'? Which happens to explain exactly what the problem is with your code? ;)
I guess there is some problem
I guess there is some problem with system. I uploaded my code 6 times(which was working fine on my system) and it showed wrong answer. Then i copied one of the given and accepted solution, changed the variable names, uploaded it again and strange its wrong answer again. Admin, could you please explain whats the problem here?
phew....finally done with
phew....finally done with it.....!!
There is no problem with the
There is no problem with the system. Your own code is repeatedly getting wrong answer because all of them do indeed give the wrong answer. Which of the submissions (copy the link from the My Submissions page so I can see it) was the one where you copied an accepted solution? I suspect you did more than just change variable names.
@stephen: I got it right. I
@stephen: I got it right. I dont know where my code my was wrong but i do know that i made some stupid change in my previous code and it got accepted, i am working on that. Anyways thanks for your reply.
giving wrong solution/// bt
giving wrong solution///
bt in my dev compiler its giving right solution..
I'm getting a "Runtime Error"
I'm getting a "Runtime Error" when submitting this program. One of the FAQ's says that "I might be using too much memory" for this particular program...but I don't agree *if that is even the case*. And if that *is* the case? I'm not going to "golf" this program down, it's good enough for a beginners program.
I think the Runtime Error is on http://www.codechef.com end. :p
That's only one reason the
That's only one reason the FAQ says you may be getting a runtime error.
Your code will get a runtime error on absolutely every single test case, including the sample input. You should try testing your code properly first ;) (Your code assumes the two numbers will be on different lines, when this is of course not the case).
http://www.codechef.com/views
http://www.codechef.com/viewsolution/381520
can anyone check this pls... its mention as runtime error. but in my system it worked successfully.
Your code fails in exactly
Your code fails in exactly the same way as I mentioned in the comment directly above yours.
My program works exactly
My program works exactly (tested your input), but when I submit it says 'Wrong Answer'.
I ran my program exactly how
I ran my program exactly how the FAQ said to.
That is because your code is
That is because your code is wrong. Read the problem statement carefully; you are missing one instruction.
Hey checking for the boundary
Hey checking for the boundary conditions and the other conditions too. sayin "Wrong answer".
#include<stdio.h>
int main()
{
int a;
float b;
scanf("%d %f",&a,&b);
if( a<=0 || a>2000 || b<0 || b>2000)
return 0;
else if((a>b) || (a%5!=0))
printf("%.2fn",b);
else
{
b= b-a -0.5;
printf("%.2fn",b);
}
return 0;
}
That's because you haven't
That's because you haven't tested the 'other conditions' properly like you say you have. As per my comment above, read the problem statement carefully.
thanx stephen !! got it !!
thanx stephen !!
got it !!
i used unsigned short int for
i used unsigned short int for X but its showin run time error. It works fine wit int. Cant i use usi for savin mem space in this program?
You can use it, but %u is not
You can use it, but %u is not how you read an unsigned short with scanf.
this code is working finely
this code is working finely in my machine , but why it is giving a runtime error? Can anyone help???
#include<stdio.h>
main()
{
float acc_bal, with_bal, prev_bal ;
int w_b, flag = 0 ;
printf("nENTER ACCOUNT BALANCE:t");
scanf("%f", &acc_bal );
printf("nENTER WITHDRAWAL BALANCE:t");
scanf("%f", &with_bal );
w_b = with_bal ;
prev_bal = acc_bal ;
if( w_b % 5 != 0 )
;
else if( with_bal > acc_bal)
printf("nINSUFFICIENT BALANCE!!! ");
else
{
acc_bal = acc_bal - with_bal - 0.50 ;
flag = 1;
}
if( flag == 1 )
{
printf("n***TRANSACTION SUCCESSFUL*** ");
printf("nUPDATED ACCOUNT BALANCE : %0.2fnWITHDRAWN : %.2fn ", acc_bal, with_bal);
}
else
printf("n ACCOUNT BALANCE : %0.2fnWITHDRAWN NOT DONEn" , prev_bal );
Read the FAQ.
Read the FAQ.
my code is running fine for
my code is running fine for all cases on linux and here its giving me the "Runtime error". can anyone explain?
thanks!
Yes. In fact, I already did,
Yes. In fact, I already did, a long time ago, in the FAQ.
can u point out the problem
can u point out the problem in my last submission?...it shows wrong ans...*HELP*
//it is showin wrong
//it is showin wrong ans....but i dont know why??..plz help
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a;
float b;
cin>>a>>b;
if(b>a)
{ if(a%5==0)
b=b-a-0.5;
else
b=b;
}
else
b=b;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<<setprecision(2)<<b;
return 0;
}
I am new to codechef. just
I am new to codechef. just came to know about it today and started submitting a program. In my comp it is working fine for all the test results. But on CodeChef it is showing Runtime Error (NZEC). i submitted so many times and i am losing interest. can anybody tell whats wrong with my code.
public class Main {
public static void main(String[] args) throws java.lang.Exception {
float withdraw =0.00f;
int balance=0;
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String input [] =r.readLine().split(" ");
withdraw = Float.parseFloat(input[0]);
balance = Integer.parseInt(input[1]);
if((withdraw<=2000 && withdraw>=0)&& (balance<=2000 && balance>0) && (balance+0.50>withdraw)&& (withdraw%5==0 && balance%5==0) )
{
System.out.println(balance-withdraw-0.50);
}
else
{
System.out.println(withdraw);
}
}
}
You should really test your
You should really test your code before asking for help. It throws an exception when run on any of the sample inputs provided.
import java.io.*; import
import java.io.*;
import java.util.*;
class atm
{
public static void main(String args[]) throws IOException
{
int ia;
String p="";
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try{
p=br.readLine();
StringTokenizer st = new StringTokenizer(p, " ");
String o;
o=st.nextToken();
int f =Integer.valueOf(o).intValue();
String l= st.nextToken();
double d = Double.valueOf(l).doubleValue();
if((0<f&&f<2000)&&(0<d&&d<2000))
{
if(f>=d||f%5!=0)
{
System.out.println(d);
}
else
{
System.out.println(d);
}
}
}
catch(NumberFormatException e)
{
}
catch(NoSuchElementException w)
{
}
}}
help me out in its precision......
sir stephen i need some help
sir stephen i need some help here ...
to use which type of datatype......for "D" i.e balance
out put is coming in one significant digit....
import java.text.*; import
import java.text.*;
import java.io.*;
import java.util.*;
class atm
{
public static void main(String args[]) throws IOException
{
String p="";
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try{
p=br.readLine();
StringTokenizer st = new StringTokenizer(p, " ");
int f =Integer.parseInt(st.nextToken());
double f1=(double)f;
String l= st.nextToken();
char[]sr ;
sr = l.toCharArray();
int p2=0;
for(int index=0; index < sr.length; index++)
{ if(sr[index]=='.')
{
p2=index;
}
}
if(sr.length==p2+3)
{
double p1= Double.valueOf(l).doubleValue();
DecimalFormat output= new DecimalFormat("#0.00");
if((0<=f&&f<=2000)&&(0<=p1&&p1<=2000))
{
if((f>=p1)||(f%5!=0)||(f==0))
{
String bang = output.format(p1);
System.out.println(bang);
}
else
{ p1=(p1-f1)-0.50d;
String bang = output.format(p1);
System.out.println(bang);
}
}
}}
catch(NumberFormatException e)
{
}
catch(NoSuchElementException w)
{
}
}}
this is edited programm if any one finds any error or exception tell me
plzzz...
it is as per the requriment..but i m getting a wrong answer error on uploading..
so pl z help...............
I am getting a runtime error
I am getting a runtime error
Please read the FAQ. You are
Please read the FAQ. You are meant to use standard input/output, not other methods of getting input.
i have tried almost 10 times
i have tried almost 10 times with every time another can you tell me whats wrong in this:
class ATM{
public static void main(String args[]) throws Exception{
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
java.io.PrintStream ps = new java.io.PrintStream(System.out);
String s = br.readLine();
String split[]=s.split(" ");
Integer cash = Integer.parseInt(split[0]);
Double bal = Double.parseDouble(split[1]);
if((bal-0.05)>=cash && cash%5==0)
System.out.printf("%.2fn",(bal-cash-0.50));
else
System.out.printf("%.2fn",bal);
}
}
There's a pretty obvious typo
There's a pretty obvious typo in your code.
Any comments on this
Any comments on this stephen?? :P ;)
Wrong solution ? lol using
Wrong solution ? lol
using System;
public class DD
{
public static void Main()
{
Double h;
string[] val = Console.ReadLine().Split(' ');
if (Double.Parse(val[0].Replace(".", ",")) % 5 == 0)
{
if (Double.Parse(val[0].Replace(".", ",")) > Double.Parse(val[1].Replace(".", ",")) - 0.50)
{
h = Double.Parse(val[1].Replace(".", ","));
}
else
{
h = Double.Parse(val[1].Replace(".", ",")) - Double.Parse(val[0].Replace(".", ",")) - Double.Parse("0,5");
}
}
else
{
h = Double.Parse(val[1].Replace(".", ","));
}
Console.WriteLine(Convert.ToString(h.ToString("N2").Replace(".", "")).Replace(",", "."));
}
}
import java.util.*; class
@stephen : thanx for your
@stephen : thanx for your guidance. I got my problem
import java.io.*; import
#include<stdio.h> #include<co
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
float j;
clrscr();
printf("enter amount withdrawn and balance:");
scanf("%d %f",&i,&j);
if(i>j || (i%5 != 0))
printf("%.2f",j);
else
printf("%.2f",(j-(i*.50)));
getch();
}
"hey i dont know why it says
"hey i dont know why it says "WRONG ANSWER:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int X;
float x;
float Y;
cout << fixed << showpoint << setprecision(2) ;
cin>>X;
cin>>Y;
x=X;
if((X>0 && X<=2000)&&(Y>=0 && Y<=2000))
{
if((X%5==0) && x<=Y+0.5)
{
cout<<(Y-x-0.5);
}
else
{
cout << Y;
}
}
return 0;
}
y am i getting a runtime
y am i getting a runtime error?
#include<stdio.h> int
#include<stdio.h>
int main()
{
int x;
float bal,y;
scanf("%f %d",&y,&x);
if((x%5==0)&&(x+.5<=y))
bal= y-(x+.5);
else
bal=y;
printf("%.2f",bal);
return 0;
}
can any one find the error that crept in this code !!
I am not able to submit my
I am not able to submit my code.
my
my solution
#include<stdio.h>
int main()
{
float a,c;
scanf("%f %f",&a,&c);
if((int)(a)%5==0&&(a+.5)<=(c))c-=a+.5;
printf("%.2fn",c);
return 0;
}
#include<stdio.h> #include<co
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
float b,c;
scanf("%d%f",&a,&b);
if(a%5==0&&a>0&&a<=2000&&b>0&&b<=2000)
{
if(a<=b+0.50)
c=b-a-0.50;
else
c=b;
}
else
c=b;
printf("%.2f",c);
getch();
return 0;
}
if the balance and amount to
if the balance and amount to be transacted are the same? then what should be the output? should it be a negative result (not a feasible one) or should the balance be returned or should it be a 'no result'?
When submitting a Solution
When submitting a Solution (C++ in my case) i'm getting the following error
"You can't submit in this language for this problem. Try link"
Please assit
My solution gives runtime
My solution gives runtime error of OTHER type, although I am able to run this on my system? What could be the possible reason? I am using python 3.1.1
#include<stdio.h> void
#include<stdio.h>
void main()
{
int m1;
float m2;
printf("enter amount(int) and initial amount(0.00)");
scanf("%d %f",m1,m2);
if((m1>0&&m<=2000)&&(m2>=0&&m2<=2000))
{
if (m1<m2)
{
if (m1%5==0)
printf("%f",m2-m1-0.5;);
else
printf("%f",m2);
}
else
printf("%f",m2);
}
#include <iostream.h>#include
#include <iostream.h>
#include <conio.h>
//using namespace std;
void main(){
float Bank_Balance=2000.00;
int Enter_Amount;
char ch;
for(;;){
do{
clrscr();
cout << "n###ATM###n";
cout << "Bank Balance Available is => "<< Bank_Balance;
cout << "nnPlease Enter the Amount In multiples Of 5$nn";
cout << "Enter the Desired Amt. => ";
/*for entering the amount*/
cin >> Enter_Amount;
if(Enter_Amount < 0 || Enter_Amount > Bank_Balance) {
cout << "Invalid Value ... Press any Key to TRY AGAIN";getch();
}
}while(Enter_Amount < 0 || Enter_Amount > Bank_Balance);
clrscr();
/*Checking if the Entered Amt. is proper or not*/
if((Enter_Amount % 5) == 0 ){
Bank_Balance -=(Enter_Amount + .50);
cout << "WithDrawal Amt. is => "<< Enter_Amount<<"$n";
cout << "Bank Balance Remaining => "<< Bank_Balance<<"$n";
cout << "nTansaction Successful !!!nPress to Proceed...";
}
/*For consideration in multiples of 5$*/
else
{
cout<<"Invalid Amt.!!!nnPlease Enter the Amount In multiples Of 5$nn";
cout<< "Please Press a Key to Process...nn";
}
getch(); clrscr();
cout << "do you want to Process for more Amount =>";
cin >> ch;
if(ch=='N' || ch== 'n') break;
}
}
what is the problem in my
what is the problem in my code why its giving errors ... Please Help !
#include <iostream>
using namespace std;
int main(){
unsigned int Bank_Balance=120.00;
unsigned int Enter_Amount=30;
float k;
cin >> Enter_Amount >> Bank_Balance;
if(Enter_Amount > Bank_Balance)
{ cout<<Bank_Balance;
}
else
{
if((Enter_Amount % 5) == 0 )
{
k= Bank_Balance -(Enter_Amount + .50);
cout<<k;
}
else
{
cout<<Bank_Balance;
}
}
return 0;
}
what is the problem in my
what is the problem in my code why its giving errors ... Please Help !
#include <iostream>
using namespace std;
int main(){
unsigned int Bank_Balance=120.00;
unsigned int Enter_Amount=30;
float k;
cin >> Enter_Amount >> Bank_Balance;
if(Enter_Amount > Bank_Balance)
{ cout<<Bank_Balance;
}
else
{
if((Enter_Amount % 5) == 0 )
{
k= Bank_Balance -(Enter_Amount + .50);
cout<<k;
}
else
{
cout<<Bank_Balance;
}
}
return 0;
}
sourabh.problem is because of
sourabh.problem is because of precision after decimal point
Hint:use iomanip header file to set precision after decimal point
Can anyone pls let me know
Can anyone pls let me know how can i optimize this code futher. I'm getting a 'time limit exceeded error'
#include "stdio.h"
void main(void){
int c;
float sum;
for(;scanf("%d %f",&c,&sum);){
if((c%5 !=0) || (sum<c)){
printf("%.2f",sum);
continue;
}
printf("%.2f",sum-(c+0.5));
}
}
You're getting time limit
You're getting time limit exceeded because your for loop will always run forever.
yes. Thnx
yes. Thnx
mine was working perfect wid
mine was working perfect wid my system but here it is showing wrong answer :(
Well, don't I feel like a
Well, don't I feel like a dumb@$$...at least now I know what to use for all input for future projects. You can't use fopen() or fread() in php for input at www.codechef.com because you need the filename (they use files for sample input and of course, we don't know the names nor the directory structures but that's to be expected). Instead, you gotta use fgets(STDIN) like listed below.
while (FALSE !== ($line = fgets(STDIN))) {
// code here for lines read by the interpreter
}
can u chek whats problem in
can u chek whats problem in that code
#include<iostream> using
#include<iostream>
using namespace std;
int main()
{
// cout<<"enter the ammont of withdrawaln";
int n;
cin>>n;
// cout<<"enter the ammount in accountn";
double a;
cin>>a;
if((double)n<a && !(n%5))
{
double b=a-(double)n-0.50;
cout<<b<<endl;
}
else
cout<<a<<endl;
system("pause");
return 0;
}
#include <iostream> #include
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
int x;
float y;
cout.precision(2);
cout.setf(ios::fixed,ios::floatfield);
cin>>x;
cin>>y;
if((x>0&&x<=2000)&&(y>=0&&y<=2000))
{
if(x%5==0&&x<y)
{
y=y-x-0.50;
cout<<y;
}
else
cout<<y;
}
return 0;
}
Giving Same Output.....
BUt Saying Wrong Answer.....Iam Frustated.:(:(
Need Help.!!!
WHy Is It so...????
hi i am new here. i have
hi i am new here. i have solved this in TC thus turbo c. but when i paste the code i am getting compilation error. i know there are some rules. but what are those?
Rule #1: Don't use Turbo C.
Rule #1: Don't use Turbo C. It doesn't comply with any of the C standards. You may find some help in the FAQ, but I suggest you get a better compiler.
Can someone please help me.
Can someone please help me. For the first two problems i have submited my code (in java) I got an compiling error saying: /sources/Main.java:5: class ATM is public, should be declared in a file named ATM.java public class ATM { ^ 1 error
What is this exactly supposed to mean? My compiler (eclipse) is not giving me any error what so ever. This is kinda of getting frustrating. Please help.
P.S All my solutions are correct and result in the same answer as examples.
You should read the FAQ.
You should read the FAQ.
<?php $wdraw=0; $tot_amount=0
<?php
$wdraw=0;
$tot_amount=0;
if(isset($_POST['num']) and isset($_POST['total'])){
$tot_amount=$_POST['total'];
if((($wdraw%5)!=0) or ($tot_amount<($_POST['num']))){
echo "Fail";
}
else{
$tot_amount=$tot_amount-$_POST['num'];
$tot_amount=$tot_amount-0.50;
echo $tot_amount;
}
}
?>
<form id="form1" name="form1" method="post" action="">
<p>
<label for="Enter number"></label>
WithDraw Amount
<input type="text" name="num" id="num" />
</p>
<p>Total Amount
<input type="text" name="total" id="total" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
my code is resulting in run
my code is resulting in run time error...... but its executing perfectly well on my compiler.plz help me in identifying the reason............
#include<stdio.h>
int main()
{
float X,Y,z;
scanf("%f%f",&X,&Y);
z=(int)X%5;
if(z!=0)
printf("n%0.2f",Y);
else if(X<Y-0.50)
printf("n%0.2f",Y-X-0.50);
else
printf("n%0.2f",Y);
return 1;
}
@divya make it return 0;
@divya
make it return 0;
#include<stdio.h>int
#include<stdio.h>
int main()
{
int x;
float y;
scanf("%d%f",&x,&y);
if((float)x>y||x%5!=0)
printf("%0.2f",y);
else
printf("%0.2f",y-x-0.5);
return 0;
}
u r giving wrong ans for my code but when i m checking it is giving write for all the inputs i tried.........
can u please tell me what's wrong with it ?
#include <stdio.h> #include
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int x;
float y;
scanf("%d",&x);
scanf("%f",&y);
if(x>2000 || y>2000 || x<0 || y<0)
{
printf("Invalid");
}
else
if(x%5!=0)
{
printf("Invalid");
}
else
if((x+0.50)>y )
{
printf("Invalid");
}
else
{
y=y-x-0.50;
printf("%.2f",y);
}
system("PAUSE");
return 0;
}
Plz help me with this error,
Plz help me with this error, it is compiling successfully on NetBeans 3.6
/sources/Main.java:13: class AccountBalance is public, should be declared in a file named AccountBalance.java public class AccountBalance { ^ 1 error
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package codechef;
/**
*
* @author AsHu
*/
import java.util.Scanner;
public class AccountBalance {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int amount;
float balance;
Scanner sc=new Scanner(System.in);
amount=sc.nextInt();
balance=sc.nextFloat();
if((balance>0 && balance<=2000)&&(amount>=0 && amount<=2000))
if(balance>(amount+.50))
if(amount%5==0)
balance-=amount+.50;
System.out.println(balance);
}
}
whats wrong in this
whats wrong in this code???its giving Runtime error during submission.
#include<stdio.h>
main(){
float b;int a,c;
scanf("%d%f",&a,&b);
if(a%5!=0||a>b||b<5.5)
printf("%fn",b);
else{
b=b-a-0.50;
printf("%fn",b);
}
}
#include <iostream> using
#include <iostream>
using namespace std;
int main()
{
int x;
float y;
cout<<"enter the money you want to withdraw::";
cin>>x;
cout<<"enter the total account balance";
cin>>y;
if((x%5)==0&&x<=y)
{
cout<<"account balance::";
cout<<(y-x-0.50);
}
else
if((x%5)!=0)
cout<<"please enter the multiple of 5::nAccount balance::"<<y;
else
if(x>y)
cout<<"Account balance::"<<y;
else
cout<<"WRONG ENTRY";
}
#include<conio.h> #include<io
#include<conio.h>
#include<iostream.h>
class Atm
{
int x
int am;
float y;
public:
void get();
void calculate();
void show();
};
void Atm::get()
{
cout<<"Enter Amount for Transaction and ur Account Balance";
cin>>x>>y;
}
void Atm::calculate()
{
if(x>=y)
{
am=y;
cout<<"You Have Insufficient Balance"<<am;
}
else if(y%5==0)
{
am=(y-x)-0.50;
}
else
{
cout<<"U HAve Entered Incorrect Amount";
am=0;
}
}
void show()
{
cout<<"Now Your Account Balance is";
cout<<am;
}
main()
{
Atm A;
A.get();
A.calculate();
A.show();
getch();
}
Hello I'm new here. Please
Hello I'm new here. Please tell me why this code is wrong :)
<?php
function withdraw($amount,$balance) {
if(($amount%5==0)&&($amount+0.50<=$balance)) {
$balance -= ($amount+0.50);
}
settype($balance,"float");
echo $balance;
}
if((0<$amount)&&($amount<=2000)) {
if((0<$balance)&&($balance<=2000)) {
withdraw($amount,$balance);
}
}
?>
why this program get wrong
why this program get wrong answer?
<?php
if(($x%5==0)&&($x+0.50<=$y)) {
$y = $y-$x-0.50;
}
printf("%.2f",$y);
?>
Please help me, I'm newbie. T__T
Please help me anyone.Why the
Please help me anyone.Why the program ATM getting wrong answer?
@Prathak: your code is not
@Prathak: your code is not accepting any values, use fgets(STDIN) to accept values
Can anyone tell me what is
Can anyone tell me what is the problem with this code. The online compiler is giving me a runtime error.
To Admin, You should make it
To Admin,
You should make it explicit that we shouldn't take care of internationalization. I was typing 120.00 (with a point) and replacing the point by a comma so that C# could parse it as a decimal. And it gave me wrong answer.
I had to look at a successfull sumbit that wasn't working for me to understand.
#include <iostream> #include
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{int wid;
float bal;
cin>>wid>>bal;
if((wid%5)==0)
{if(wid<bal)
{bal=bal-wid;
bal-=0.50;
cout<<fixed<<setprecision(2)<<bal;
}
else
cout<<fixed<<setprecision(2)<<bal;
}
void main(){ int
void main()
{
int wd,tot,rem=0;
printf("Enter the total amount");
scanf("%d", &tot);
printf("Enter amount withdrawn");
scanf("%d", &wd);
if(tot>wd)
{
if(wd%5==0)
{
rem=tot-(wd+.50);
printf("Your Balance is = %d",rem);
}
else
printf("Not correct amount to withdraw");
}
else
printf("Total cant be more than Withdrawl amount");
}
This problem can't be
This problem can't be resolved..
#include<stdio.h> #include<co
#include<stdio.h>
#include<conio.h>
void main()
{
float y,total;int x;
printf("Enter the cash to withdarw and initial balancen");
scanf("%dt%f",&x,&y);
if((x<=2000)&&(y<=2000))
{
if(x>y)
printf("Insufficent fundsn");
else
if(x%5!=0)
{
printf("Incurrect withrawal ammount(not multiple or 5)n");
}
else
{
total=(y-x)-.50;
printf("Transection succesfuln%.2f",total);
}
}
getch();}
on executing 5.51-(5+.5) its
on executing 5.51-(5+.5) its giving 009999999999999787 which is according to you a wrong ans? i think...
can anyone tell me why wrong
can anyone tell me why wrong ans?
import java.text.DecimalFormat;
import java.util.Scanner;
class ATM {
public static void main(String[] args) throws Exception{
Scanner s=new Scanner(System.in);
java.text.DecimalFormat df=new DecimalFormat("####.##");
int n=s.nextInt();
double m=s.nextDouble();
if((m>0)&&(m<=2000)&&(0<n) &&(n<=2000))
{
if((n%5==0) &&((n+0.50)<=m))
{
m=m-n-0.50;
m=df.parse(df.format(m)).doubleValue();
System.out.println("balance is"+m);
}
else{
System.out.println(m);
}
}
else{
System.out.println("wrong value");
}
}
}
no check for (0 < X <= 2000)
no check for (0 < X <= 2000) &&(0 < y <= 2000)
in accepted programs i've added this check n i'm wrong lolzzzz:)
#include<iostream.h>#include<
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
void main()
{
float x = 120.00;
int y;
clrscr();
cout<<"Enter withdraw ammount & balance";
cin>>y>>x;
if(x>2000 | y>2000)
{
cout<<"Wrong input";
getch();
exit(0);
}
if(y%5!=0)
{
cout<<"Wrong enter withdraw ammount";
getch();
exit(0);
}
else if(y>=x)
{
printf("insufficient ammount = %.2f",x);
getch();
exit(0);
}
else
{
x = x-y-.5;
printf("total ammount = %.2f",x);
getch();
}
}
#include<iostream.h>#include<
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
void main()
{
float x = 120.00;
int y;
clrscr();
cout<<"Enter withdraw ammount & balance";
cin>>y>>x;
if(x>2000 | y>2000)
{
cout<<"Wrong input";
getch();
exit(0);
}
if(y%5!=0)
{
cout<<"Wrong enter withdraw ammount";
getch();
exit(0);
}
else if(y>=x)
{
printf("insufficient ammount = %.2f",x);
getch();
exit(0);
}
else
{
x = x-y-.5;
printf("total ammount = %.2f",x);
getch();
}
}
Yaar dis code is running on
Yaar dis code is running on my comp but here it is giving wrong answer if u know what can be the error pls post.
import java.io.*;
class atm{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
String words[] = line.split(" ");
int tran = Integer.parseInt(words[0]);
double balance = Double.parseDouble(words[1]);
if(tran%5!=0) System.out.println(String.format("%1$.2f",balance));
if(balance-0.50-tran<0)System.out.println(String.format("%1$.2f",balance));
if(balance-0.50-tran>=0 && tran%5==0) System.out.println(String.format("%1$.2f",balance-0.50-tran));
}
}
import
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner atm = new Scanner(System.in);
int withdraw = atm.nextInt();
float balance = atm.nextFloat();
if(withdraw%5 == 0 && withdraw < balance)
System.out.println(balance-withdraw-.50);
else
System.out.println(balance);
}
}
I don't get it I run this code in eclipse and it works perfect with the right answer but the submission on this site keeps on saying wrong answer
#include<stdio.h> int
#include<stdio.h> int main() { int x; float y; scanf("%d",&x); scanf("%f",&y); if(x%5==0 && x+0.50<=y) printf("%.2f",y-x-0.50); else printf("%.2f",y); }
#include<stdio.h> int main() { int x; float y; scanf("%d",&x); scanf("%f",&y); if(x%5==0 && (y-x-0.50>=0)) printf("%.2f",y-x-0.50); else printf("%.2f",y); }
What is the differnence between
x+0.50<=y
y-x-0.50>=0
I am able to execute the first one but not the second one...:(
what's wrong with
what's wrong with mine??
please help!
#include <stdio.h>
int main (void)
{
int X;
float Y;
//withdraw value
scanf ("%d",&X);
//account balance
scanf ("%f",&Y);
if (X>=Y){
printf("%.2f",Y);
} else {
if ((X<(Y+0.50)) && ((X%5)==0) && (0<X<=2000)){
Y=Y-(X+0.50);
printf ("%.2f",Y);
}else{
printf("%.2f",Y);
}
}
return 0;
}
what's wrong with
what's wrong with mine??
please help!
#include <stdio.h>
int main (void)
{
int X;
float Y;
//withdraw value
scanf ("%d",&X);
//account balance
scanf ("%f",&Y);
if (X>=Y){
printf("%.2f",Y);
} else {
if ((X<(Y+0.50)) && ((X%5)==0) && (0<X<=2000)){
Y=Y-(X+0.50);
printf ("%.2f",Y);
}else{
printf("%.2f",Y);
}
}
return 0;
}
Why does it give runtime
Why does it give runtime
#include main() { int n;
It gives me a runtime error
#include int main() { int
'm getting a run-time error
What is meaning of "problem
Hi, my submitted solution is
my program is running in dev
my program is running in dev
my program is running
#include int main() { int
hi Guys ,, i have made prog
@adiki....hope u r not
dont know whats the problem!!
hello, I've been trying to do
still posting the correct
I get a runtime error with
whoops, nevermind didn't see
can anyone tell me , what's
Wrong Answer
hi admin. i tried.. and got
#!/bin/bash #set -x if [
WTF it is giving wrong answer
import
import java.io.*; class
Hi, I have just entered a
Hey guys! If you're getting
I mean, in these