 # Help needed with ATM CodeChef problem

Hi everyone,

I created an `if` statement that produces the proper output, but I am having trouble turning this solution into a function with standard inputs. In my solution, I am assigning input values, which I assume is not allowed and is the reason it is rejected every time.

The solution is written in the R language.

``````withdraw <- 30
balance <- 120.00

if(withdraw %% 5 == 0 & balance >= x + 0.50){
balance - withdraw - 0.50
}else{
withdraw
}
format(z, nsmall = 2)

 89.5
 "89.50"``````

you can use readline() to take input

withdraw = as.integer(withdraw);

balance = as.integer(withdraw);

Thank you. Would this be within the function or outside it? I am using your suggestion and all it is doing is freezing up my RStudio.

``````withdraw = readline();
withdraw = as.integer(withdraw);
balance = as.integer(withdraw);
atm <- function(withdraw, balance){
if(withdraw %% 5 == 0 & balance >= withdraw + 0.50){
balance - withdraw - 0.50
}else{
withdraw
}
}
atm(30, 120.00)``````

con=file(stdin, r)
withdr<-scan(file=con, what=integer(0), n=1)
bal<-scan(file=con, what=integer(0), n=1)
atm <- function(withdraw, balance){
if(withdraw %% 5 == 0 & balance >= withdraw + 0.50){
balance - withdraw - 0.50
}else{
withdraw
}
}
atm(withdr, bal)

Try this code

Hmmm. This code also freezes my RStudio. Also, when submitted to CodeChef returns wrong answer. Any ideas?

The problem with RS studio is that this requires input from stdin and you are probably not providing any input. hence the freezing. As for the wrong answer i have only provided the code to accept input and not altered your logic in any way.

and dont forget to enter input in the STDIN tab before executing!

When you say input in STDIN, are you referring to the:

con=file(stdin, r)

should be:

``````con=file("30, 120.00", "r")
``````

Ultimately, I want to see what the correct acceptable solution looks like so I can implement that in future questions. This is my first attempt using R as a functional programming language for CodeForces.

no you are not supposed to set the variables like that. Value of balance and withdrawal will keep changing so you need to read the input from “stdin” and set the values accordingly.

And if language is not an issue that i would suggest to use faster languages like C++ or JAVA.

I used the code you provided the main.r tab and the following in the STDIN tab on separate lines:

30
120

When I hit execute on both tabs, noting happens.

input in same line and spac seperated and no decimals.
so
30 120
will work

When executing in CodingGround, all I get for both tabs in the result side is:

\$Rscript main.r

With no output below. I would upload screenshots but I can’t as a new user.

Also, how on earth would I submit this as a solution to CodeForces? And can’t I use your original suggestion in RStudio? Somehow utilizing this:

``````withdraw = readline();
withdraw = as.integer(withdraw);