You are not logged in. Please login at to post your questions!


ATM problem

PLEASE ANSWER IMMEDIATELY i am a new user and the problem i am trying to solve is ATM this is my programme

int main ()
    int a, b;
    if(a<=2000 && b<=2000 &&a>0 && b>=0){
    std::cout<<"invalid input";

find the error please

asked 19 Nov '14, 09:25

mithunmuru's gravatar image

accept rate: 0%

converted to question 19 Nov '14, 12:19

betlista's gravatar image

3★betlista ♦♦

first of all your account balance should be a floating or double type value.since every time an amount of 0.50 $ is to be charged by ATM therefore you should add if(a+0.50<b) second="" there="" is="" no="" need="" to="" write="" if(a<="2000" &&="" b<="2000" &&a="">0 && b>=0)as not asked by the program.


answered 21 Nov '14, 15:20

gagan1998_oct's gravatar image

accept rate: 15%

@mithunmuru Leaving the logic behind, the very first thing that you should learn is indenting your code. Not only the code looks clean but it helps you to see through your code for logical and syntactical error but also helps other people you may ask for help.

Secondly you must understand that you don't have to check the conditions given on the test cases. Like the this piece of code in your program - if(a<=2000 && b<=2000 && a>0 && b>=0) is useless. You must think about your logic keeping in mind that the codechef judge will only give the given values as test cases and hence you don't have to check for such conditions and write statements like these - std::cout<<"invalid input"

Now another thing to keep in mind while writing your program is output format. It is possible that your logic for a particular question is absolutely correct but the output format is wrong then no matter what you do you will get a wrong answer every time.

These were some basic things you should keep in mind. Regarding the error in your code the condition that you applied in a and b is wrong. Try to run your code for different varieties of test cases and check what should be the condition on a and b. Think hard on this line form the question - "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)".


answered 19 Nov '14, 10:48

insaynasasin's gravatar image

accept rate: 0%

use this code. i got my answer correct.

include <iostream>


using namespace std; int main() { float y; int x; cin>>x; cin>>y; if(x>=0&&x<=2000&&y>=0&&y<=2000) { if((x+0.50)<y&&x%5==0) y=y-x-0.50; cout<<y; }

This answer is marked "community wiki".

answered 21 Nov '14, 15:36

namankumar's gravatar image

accept rate: 0%

Hope this will help you

(21 Nov '14, 15:37) namankumar0★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 19 Nov '14, 09:25

question was seen: 684 times

last updated: 21 Nov '14, 15:37