ATM problem

atm

#1

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


#2

@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)”.


#3

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.


#4

use this code. i got my answer correct.

include

include

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


#5

Hope this will help you