If statement in R | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

If statement in R

x <- readLines('stdin') num <- as.integer(x[1]) x <- 2 if(x%%2==0) { print("even") } else { print("odd") } Where is the error in this program?

9th Sep 2021, 10:27 PM
Ammara Tayyab
3 Answers
+ 4
You're making no use of the input. Since you assign the value 2 to x the code will always print "even", no matter what the input is.
9th Sep 2021, 10:45 PM
Simon Sauter
Simon Sauter - avatar
+ 4
x <- readLines('stdin') num <- as.integer(x[1]) if(num%%2==0) print("even") else print("odd")
9th Sep 2021, 11:36 PM
SoloProg
SoloProg - avatar
+ 2
Thank you
10th Sep 2021, 8:03 AM
Ammara Tayyab