### QUESTION 07
## Topic: Lecture 7, Slide 9
## Question: there is an R code which prints the state of the water. The following code, Temp <- "readline(prompt = " ") defines the input as a character and the result always becomes vapor. I changed the code as following: Temp <- as.integer(readline(prompt = " ")). Is this a good approach or did I do anything wrong in the first code?
# Temp <- as.integer(readline(prompt = "Enter water temperature: "))
# if(Temp <= 0){
# print("This is ice.")
# } else {
# if(Temp < 100){
# print("This is liquid.")
# } else {
# print("This is vapor.")
# }
# }
## Answer: You correctly define the input as integer. However, here we need a function that contains Temp and all the conditions (if,else). Once the function is declared, you may initiate an interactive session using interactive() and incorporate your function.
Temp_fun <- function () {
Temp <- as.integer(readline(prompt = "Enter water temperature: "))
if(Temp <= 0){
print("This is ice.")
} else {
if(Temp < 100){
print("This is liquid.")
} else {
print("This is vapor.")
}
}}
if(interactive()) Temp_fun() # you may also reuse this command for other temperature values