You are not logged in. Please login at www.codechef.com 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

#include<iostream>
int main ()
{   
    int a, b;
    std::cin>>a>>b;
    if(a<=2000 && b<=2000 &&a>0 && b>=0){
    if(a<=b){
        if(a%5==0){
            std::cout<<(b-(a+0.50));
            }
        else
            std::cout<<b;}
    else 
    std::cout<<b;
    }
    else
    std::cout<<"invalid input";
}

find the error please

asked 19 Nov '14, 09:25

mithunmuru's gravatar image

0★mithunmuru
1
accept rate: 0%

converted to question 19 Nov '14, 12:19

betlista's gravatar image

3★betlista ♦♦
16.9k49115225


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.

link

answered 21 Nov '14, 15:20

gagan1998_oct's gravatar image

1★gagan1998_oct
1713
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)".

link

answered 19 Nov '14, 10:48

insaynasasin's gravatar image

1★insaynasasin
1054811
accept rate: 0%

use this code. i got my answer correct.

include <iostream>

include<iomanip>

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; }

link
This answer is marked "community wiki".

answered 21 Nov '14, 15:36

namankumar's gravatar image

0★namankumar
2521624
accept rate: 0%

Hope this will help you

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×190

question asked: 19 Nov '14, 09:25

question was seen: 684 times

last updated: 21 Nov '14, 15:37